Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop to Main - publish 2.0.0 #21

Merged
merged 36 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ac5d34e
configure what host is allowed through
floyd-may Apr 27, 2022
66e0bba
fix origin/Develop check in GH action
floyd-may Apr 29, 2022
9371b47
random syntax issue in GH action
floyd-may Apr 29, 2022
667ccfe
schrodingbug in GH action config - how did that ever work?
floyd-may Apr 29, 2022
3af6d96
only push to nuget if on origin/Develop
floyd-may Apr 30, 2022
37b1a14
retry only push to nuget if on origin/Develop
floyd-may Apr 30, 2022
87ef7ce
fix syntax error
floyd-may Apr 30, 2022
6b3e0b1
I'm a programmer, i understand booleans. really.
floyd-may Apr 30, 2022
50efb3c
allow multiple allowed hosts
floyd-may Apr 30, 2022
fdf99e5
bumping the version. Offically kicks of the 2.0 RC. Still need to cut…
calebjenkins May 1, 2022
dfa039d
Merge pull request #11 from calebjenkins/allow-non-localhost
calebjenkins May 1, 2022
0b5160c
fix CI actions workflow
floyd-may May 1, 2022
628c792
Merge pull request #14 from calebjenkins/ci-publish-nuget
calebjenkins May 1, 2022
c8325c4
build nuget for both netcoreapp3.1 and net6.0
floyd-may May 1, 2022
eed43bf
remove unneeded conditional package refs
floyd-may May 1, 2022
ee61fb3
made test HostRewriteSettings.Host string? to rmove compiler warning.
calebjenkins May 1, 2022
9a460d9
moved FakeAuth setting List<Claims> to IList<Claims for consistancy.
calebjenkins May 1, 2022
ee27059
removing obsolete extension methods
calebjenkins May 1, 2022
33b153d
update to readme for 2.0.0
calebjenkins May 1, 2022
4014740
update samples to CI nuget and StartUp class
calebjenkins May 2, 2022
f24ea7d
Merge pull request #15 from calebjenkins/update-nuget-targeting
calebjenkins May 2, 2022
375bb4e
Merge branch 'Develop' into dev/feature-12-Prep-for-2.0
calebjenkins May 2, 2022
be0b266
adding net5 to nuget targets and updating readme with additonal links
calebjenkins May 2, 2022
66079c2
Merge pull request #16 from calebjenkins/dev/feature-12-Prep-for-2.0
calebjenkins May 2, 2022
cd771eb
re-arranging net6 vs net 5 - only net 5 was showing up in nuget
calebjenkins May 2, 2022
3afc586
can't get 5.0 and 6.0 to both show in nuget. screw it, only care abou…
calebjenkins May 2, 2022
f5430a3
update readme format for History
calebjenkins May 2, 2022
670d9d0
additonal context in readme history
calebjenkins May 2, 2022
69e1fc0
moving IEnumerable to IList for ApprovedHosts
calebjenkins May 2, 2022
ce2b550
Merge pull request #18 from calebjenkins/dev/feature-13-evaluating-2.0
calebjenkins May 2, 2022
0423e4a
update samples to always reference latest CI nuget package to catch i…
calebjenkins May 2, 2022
99e1975
Merge pull request #19 from calebjenkins/dev/feature-14-move-nuget-sa…
calebjenkins May 2, 2022
9f884d3
adding AllowedHosts to SampleWeb App comments
calebjenkins May 3, 2022
b323166
Merge pull request #20 from calebjenkins/dev/feature-15-final-2.0-eval
calebjenkins May 3, 2022
43b5079
Updating wf to fix error. Using Floyd-fu from dev-ci and pplying to main
calebjenkins May 3, 2022
575f016
Merge branch 'Develop' of https://github.com/calebjenkins/FakeAuth in…
calebjenkins May 3, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions .github/workflows/dev-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ on:
- '**.md'
workflow_dispatch:

env:
Nuget_Key: secrets.FAKEAUTH_NUGET_KEY
Nuget_URL: "https://api.nuget.org/v3/index.json"
env:
Nuget_Key: secrets.FAKEAUTH_NUGET_KEY
Nuget_URL: "https://api.nuget.org/v3/index.json"

jobs:
build:
Expand Down Expand Up @@ -78,13 +78,23 @@ jobs:
- name: Test
run: dotnet test --configuration Release --no-build

- name: Verify commit exists in origin/Develop
run: git branch --remote --contains | grep origin/Develop
- name: Detect if workflow is running on origin/Develop
id: detect_develop
run: git rev-parse HEAD | grep $(git rev-parse origin/Develop)
continue-on-error: true

- name: Verify is based on origin/Develop to ensure PRs are correctly targeted
# List commits that are ahead of origin/Develop through HEAD and look for the tip of the current branch.
# If HEAD isn't ahead of origin/Develop, the git log bit will be empty and grep will fail
run: git log origin/Develop..HEAD | grep $(git rev-parse --short HEAD)
if: ${{ steps.detect_develop.outcome == 'failure' }}

- name: Pack
run: dotnet pack --configuration Release /p:Version=${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${BUILD_NUMBER} --include-symbols --output .
if: ${{ steps.detect_develop.outcome == 'success' }}


- name: Push to Nuget
if: ${{ steps.detect_develop.outcome == 'success' }}
# run: dotnet nuget push *.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.FAKEAUTH_NUGET_KEY}}
run: dotnet nuget push FakeAuth.${{steps.get_version.outputs.RELEASE_VERSION}}-ci-${BUILD_NUMBER}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${{secrets.FAKEAUTH_NUGET_KEY}}
2 changes: 1 addition & 1 deletion .github/workflows/main-ci-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fetch-depth: 0

- name: Verify commit exists in origin/main
run: git branch --remote --contains | grep origin/main
run: git log origin/Main..HEAD | grep $(git rev-parse --short HEAD)

- name: Get version
id: get_version
Expand Down
8 changes: 2 additions & 6 deletions FakeAuth.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
Build.ps1 = Build.ps1
.github\workflows\ci.yml = .github\workflows\ci.yml
Directory.Build.props = Directory.Build.props
LICENSE = LICENSE
NuGet.Config = NuGet.Config
Push.ps1 = Push.ps1
README.md = README.md
.github\workflows\release.yml = .github\workflows\release.yml
.github\workflows\dev-ci.yml = .github\workflows\dev-ci.yml
.github\workflows\main-ci-test-publish.yml = .github\workflows\main-ci-test-publish.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{91A40EAF-50BB-4778-AC9D-5D62B7BFD93E}"
Expand Down
219 changes: 113 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,107 +1,114 @@
# FakeAuth

[![.github/workflows/dev-ci.yml](https://github.com/calebjenkins/FakeAuth/actions/workflows/dev-ci.yml/badge.svg?branch=Develop)](https://github.com/calebjenkins/FakeAuth/actions/workflows/dev-ci.yml)
[![.github/workflows/main-ci-test-publish.yml](https://github.com/calebjenkins/FakeAuth/actions/workflows/main-ci-test-publish.yml/badge.svg?branch=main)](https://github.com/calebjenkins/FakeAuth/actions/workflows/main-ci-test-publish.yml)
[![NuGet](https://img.shields.io/nuget/dt/fakeauth.svg)](https://www.nuget.org/packages/fakeauth)
[![NuGet](https://img.shields.io/nuget/vpre/fakeauth.svg)](https://www.nuget.org/packages/fakeauth)


![FakeAuth Logo](./assets/logo/FakeAuth_med.png "FakeAuth - for simple oAuth .NET 6 development")

a .NET Core library to make developing offline for OAuth and OIDC much easier.

Developing with OAuth or OIDC - takes about 30 minutes of set up work just to get going; with FakeAuth, it's one line of code.

Supports custom Claims and Profiles that can be swapped in during development of your application.

Examples in the [Samples Folder](https://github.com/calebjenkins/FakeAuth/tree/main/Samples). More details on [why this was built on this blog post](https://developingux.com/introducing-fakeauth/).

### Installing FakeAuth

You should install [FakeAuth with NuGet](https://www.nuget.org/packages/FakeAuth):

Install-Package FakeAuth

Or via the .NET Core command line interface:

dotnet add package FakeAuth

Either command, from Package Manager Console or .NET Core CLI, will download and install FakeAuth and all required dependencies.

### Using FakeAuth

In an ASP.NET Core Application, you can configure FakeAuth in the Startup Class:

services.AddAuthentication().AddFakeAuth();

That will give you a default profile. In fact, the above is exactly the same as doing this:

services.AddAuthentication().AddFakeAuth<DefaultProfile>();

You can create custom profiles by implementing the interface [IFakeAuthProfile](https://github.com/calebjenkins/FakeAuth/blob/main/src/FakeAuth/Profiles/IFakeAuthProfile.cs),
or you can inline your custom claims directly:

```csharp
services.AddAuthentication().AddFakeAuth((options) =>
{
options.Claims.Add(new Claim(ClaimTypes.Name, "Fake User"));
options.Claims.Add(new Claim(ClaimTypes.Role, "Expense_Approver"));
options.Claims.Add(new Claim("Approval_Limit", "25.00"));
options.Claims.Add(new Claim("Approval_Currency", "USD"));
options.Claims.Add(new Claim("Preffered_Location", "Disney Island"));
});
```
See more of these examples in the [SampleWeb application](https://github.com/calebjenkins/FakeAuth/tree/main/Samples/FakeAuth.SampleWeb).

### Testing with FakeAuth

FakeAuth works great with ASP.Net's testing framework. For some examples, take a look at the
[FakeAuth.IntegrationTests project](https://github.com/calebjenkins/FakeAuth/blob/main/Tests/FakeAuth.IntegrationTests).

In particular, you can set the FakeAuth claims for a specific `HttpClient` using `SetFakeAuthClaims(...)`:

```csharp
client.SetFakeAuthClaims(
new Claim(ClaimTypes.Name, "Joe Manager"),
new Claim(ClaimTypes.Role, "Manager")
);
```

You can also re-use any profiles that impliment `IFakeAuthProfile` directly on your `HttpClient`:
```csharp
client.SetFakeAuthClaims<DefaultProfile>();
```

This lets you write tests that validate your authorization works as intended with and without the required claims.

### .NET 6

In .NET 6 you are no longer required to use a StartUp class. You can still use FakeAuth directly in the [Program class](https://github.com/calebjenkins/FakeAuth/blob/main/Samples/nuget.SampleWeb6.0/Program.cs):

```csharp
builder.Services.AddAuthentication().AddFakeAuth();
```

### Use Cases - for OAuth/Claims based .NET Core applications

- To get started building your application as quickly as possible.
- For POCs that you want to try out without registering your application in an Identity Provider.
- For running and developing locally without internet access.
- For Demo based applications that you want people to download and run - without needing to set up a production identity service first, or without sharing your application id/client secret information.

### Not for - FakeAuth can not be used in production
- Do not use FakeAuth in a production enviroment
- FakeAuth will only work on http://localhost/ - it's intended to be a development tool.
- You will want to transition to an actual OAuth / Claims provider before you go to Production. Starting with Fake Auth can help you establish and document which claims your application will rely on.

## Contributing to FakeAuth

Please target any PRs to the `Develop` branch.

## History
Prior to `version 1.2.0` only `services.UseFakeAuth()` was supported. This is considered obsolete, and will be dropped in version 2.0.0 moving forward.

Starting with `version 1.2.0 +` please use the `services.AddAuthentication().AddFakeAuth()` extension methods.
This was done to more syntactically align FakeAuth with other authentication mechanisms and idioms.

# FakeAuth

[![.github/workflows/dev-ci.yml](https://github.com/calebjenkins/FakeAuth/actions/workflows/dev-ci.yml/badge.svg?branch=Develop)](https://github.com/calebjenkins/FakeAuth/actions/workflows/dev-ci.yml)
[![.github/workflows/main-ci-test-publish.yml](https://github.com/calebjenkins/FakeAuth/actions/workflows/main-ci-test-publish.yml/badge.svg?branch=main)](https://github.com/calebjenkins/FakeAuth/actions/workflows/main-ci-test-publish.yml)
[![NuGet](https://img.shields.io/nuget/dt/fakeauth.svg)](https://www.nuget.org/packages/fakeauth)
[![NuGet](https://img.shields.io/nuget/vpre/fakeauth.svg)](https://www.nuget.org/packages/fakeauth)


![FakeAuth Logo](./assets/logo/FakeAuth_med.png "FakeAuth - for simple oAuth .NET 6 development")

a .NET Core library to make developing offline for OAuth and OIDC much easier.

Developing with OAuth or OIDC - takes about 30 minutes of set up work just to get going; with FakeAuth, it's one line of code.

Supports custom Claims and Profiles that can be swapped in during development of your application.

Examples in the [Samples Folder](https://github.com/calebjenkins/FakeAuth/tree/main/Samples). More details on [why this was built on this blog post](https://developingux.com/introducing-fakeauth/) and [additional articles](https://developingux.com/fakeauth).

### Installing FakeAuth

You should install [FakeAuth with NuGet](https://www.nuget.org/packages/FakeAuth):

Install-Package FakeAuth

Or via the .NET Core command line interface:

dotnet add package FakeAuth

Either command, from Package Manager Console or .NET Core CLI, will download and install FakeAuth and all required dependencies.

### Using FakeAuth

In an ASP.NET Core Application, you can configure FakeAuth in the Startup Class:

services.AddAuthentication().AddFakeAuth();

That will give you a default profile. In fact, the above is exactly the same as doing this:

services.AddAuthentication().AddFakeAuth<DefaultProfile>();

You can create custom profiles by implementing the interface [IFakeAuthProfile](https://github.com/calebjenkins/FakeAuth/blob/main/src/FakeAuth/Profiles/IFakeAuthProfile.cs),
or you can inline your custom claims directly:

```csharp
services.AddAuthentication().AddFakeAuth((options) =>
{
options.Claims.Add(new Claim(ClaimTypes.Name, "Fake User"));
options.Claims.Add(new Claim(ClaimTypes.Role, "Expense_Approver"));
options.Claims.Add(new Claim("Approval_Limit", "25.00"));
options.Claims.Add(new Claim("Approval_Currency", "USD"));
options.Claims.Add(new Claim("Preffered_Location", "Disney Island"));
});
```
See more of these examples in the [SampleWeb application](https://github.com/calebjenkins/FakeAuth/tree/main/Samples/FakeAuth.SampleWeb).

### Testing with FakeAuth

FakeAuth works great with ASP.Net's testing framework. For some examples, take a look at the
[FakeAuth.IntegrationTests project](https://github.com/calebjenkins/FakeAuth/blob/main/Tests/FakeAuth.IntegrationTests).

In particular, you can set the FakeAuth claims for a specific `HttpClient` using `SetFakeAuthClaims(...)`:

```csharp
client.SetFakeAuthClaims(
new Claim(ClaimTypes.Name, "Joe Manager"),
new Claim(ClaimTypes.Role, "Manager")
);
```

You can also re-use any profiles that implement `IFakeAuthProfile` directly on your `HttpClient`:
```csharp
client.SetFakeAuthClaims<DefaultProfile>();
```

This lets you write tests that validate your authorization works as intended with and without the required claims.

### .NET 6

In .NET 6 you are no longer required to use a StartUp class. You can still use FakeAuth directly in the [Program class](https://github.com/calebjenkins/FakeAuth/blob/main/Samples/nuget.SampleWeb6.0/Program.cs):

```csharp
builder.Services.AddAuthentication().AddFakeAuth();
```

### Use Cases - for OAuth/Claims based .NET Core applications

- To get started building your application as quickly as possible.
- For POCs that you want to try out without registering your application in an Identity Provider.
- For running and developing locally without internet access.
- For Demo based applications that you want people to download and run - without needing to set up a production identity service first, or without sharing your application id/client secret information.

### Not for - FakeAuth can not be used in production
- Do not use FakeAuth in a production environment
- FakeAuth will only work on http://localhost/ by default - it's intended to be a development tool.
- You will want to transition to an actual OAuth / Claims provider before you go to Production. Starting with Fake Auth can help you establish and document which claims your application will rely on.

## Contributing to FakeAuth

Please target any PRs to the `Develop` branch.

## History
### Changes in `version 2.0.0`
- Removed the obsolete extension methods from `version 1.2.0`. Must use `AddAuthentication().AddFakeAuth()` methods now.
- Fixed typo in the `HttpClientExtensions` extension class from `SetFakeAuthClaimns` to `SetFakeAuthClaims`
- **New Feature:** We added a new `AllowedHosts` property to the `FakeAuthOptions` class. Previously, only localhost testing was supported, with `2.0.0` and forward, specific hosts can be configured to support more testing scenarios.


### Version 1.2.0
Prior to `version 1.2.0` only `services.UseFakeAuth()` was supported. This is considered obsolete, and will be dropped in version 2.0.0 moving forward.

Starting with `version 1.2.0 +` please use the `services.AddAuthentication().AddFakeAuth()` extension methods.
This was done to more syntactically align FakeAuth with other authentication mechanisms and idioms.

This history section will be removed (more likely updated) when we get to `2.0.0 +`
3 changes: 3 additions & 0 deletions Samples/FakeAuth.SampleWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void ConfigureServices(IServiceCollection services)
// options.Claims.Add(new Claim("Approval_Limit", "25.00"));
// options.Claims.Add(new Claim("Approval_Currency", "USD"));
// options.Claims.Add(new Claim("Preffered_Location", "Disney Island"));

// options.AllowedHosts.Add("localhost");
// options.AllowedHosts.Add("container-host");
//});

services.AddControllersWithViews(options =>
Expand Down
2 changes: 1 addition & 1 deletion Samples/nuget.SampleWeb3.1/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Startup(IConfiguration configuration)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.UseFakeAuth();
services.AddAuthentication().AddFakeAuth();
//services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
// .AddAzureAD(options => Configuration.Bind("AzureAd", options));

Expand Down
22 changes: 11 additions & 11 deletions Samples/nuget.SampleWeb3.1/nuget.SampleWeb3.1.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-nuget.SampleWeb3._1-B38114C5-BA75-491A-9103-DFFAFCC2E8D3</UserSecretsId>
<WebProject_DirectoryAccessLevelKey>0</WebProject_DirectoryAccessLevelKey>
<RootNamespace>nuget.SampleWeb3._1</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UserSecretsId>aspnet-nuget.SampleWeb3._1-B38114C5-BA75-491A-9103-DFFAFCC2E8D3</UserSecretsId>
<WebProject_DirectoryAccessLevelKey>0</WebProject_DirectoryAccessLevelKey>
<RootNamespace>nuget.SampleWeb3._1</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FakeAuth" Version="*" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="3.1.21" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.AzureAD.UI" Version="3.1.21" />
<PackageReference Include="FakeAuth" Version="*-ci*" />
</ItemGroup>

</Project>
Loading