Skip to content

Commit 6ed0d09

Browse files
committed
update readme so it matches the new stuff
1 parent aa243d2 commit 6ed0d09

3 files changed

Lines changed: 109 additions & 35 deletions

File tree

README.md

Lines changed: 109 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ The build environment for this project is on Azure DevOps and can be found here
3333
| Beta | [![Beta](https://vsrm.dev.azure.com/kirkone/_apis/public/Release/badge/b206bf59-b281-4d06-91c3-3877c3aeaaf9/1/2)](https://dev.azure.com/kirkone/KK.AspNetCore.EasyAuthAuthentication/_releases2?definitionId=1&_a=releases) |
3434
| Release | [![Release](https://vsrm.dev.azure.com/kirkone/_apis/public/Release/badge/b206bf59-b281-4d06-91c3-3877c3aeaaf9/1/3)](https://dev.azure.com/kirkone/KK.AspNetCore.EasyAuthAuthentication/_releases2?definitionId=1&_a=releases) |
3535

36-
## Usage
36+
## Quickstart
3737

38-
> **INFO**: For detailed usage information please have a look in the `samples` folder.
39-
40-
### Startup.cs
41-
42-
Add something like this in the `public void ConfigureServices` method:
38+
In your Startup of your WebApp you must configure your authentication schemes and add easy auth to you dependency injection. The easiest way is to use the configuration of your web app. This can be done in the `ConfigureServices` method in your `Startup`.
4339

4440
```csharp
4541
services.AddAuthentication(
@@ -48,20 +44,51 @@ services.AddAuthentication(
4844
options.DefaultAuthenticateScheme = EasyAuthAuthenticationDefaults.AuthenticationScheme;
4945
options.DefaultChallengeScheme = EasyAuthAuthenticationDefaults.AuthenticationScheme;
5046
}
51-
).AddEasyAuth();
47+
).AddEasyAuth(this.Configuration);
5248
```
5349

54-
and this to the `public void Configure` method before `app.UseMvc...`:
50+
The next you must add the easy auth middleware to the ASP.NET pipeline. This can be enabled by the folling section in your `Configure`method in the `Startup`:
5551

5652
```csharp
5753
app.UseAuthentication();
5854
```
5955

60-
This will enable the `EasyAuthAuthenticationHandler` in your app.
56+
> Warning: make sure you add the `UseAuthentication` in the right order for your use case.
57+
58+
The last thing is to add the following section in the `appsettings.json` to enabled the basic providers:
59+
60+
```json
61+
"easyAuthOptions": {
62+
"providerOptions": [
63+
{
64+
"ProviderName": "EasyAuthForAuthorizationTokenService",
65+
"Enabled": true
66+
},
67+
{
68+
"ProviderName": "EasyAuthWithHeaderService",
69+
"Enabled": true
70+
}
71+
]
72+
}
73+
```
74+
75+
After this you can use your app can translate the claims of easy auth for azure AD by it's own.
6176

62-
### Controller.cs
77+
### Configure Azure App Service
6378

64-
In your controllers you can access the `User` property as usual:
79+
In general you need a windows based App Service Plan to get this working. There is no Easy Auth implementation in the linux based app service plans!
80+
81+
> Information: for current documentation about this azure feature see [here](https://docs.microsoft.com/en-us/azure/app-service/overview-authentication-authorization).
82+
83+
The first step is enable the authentication feature in azure. It is important to disabled anonymous requests!
84+
85+
![basic auth settings](docs/assets/easyauth-config.png)
86+
87+
Then you need the connection to your azure active directory. (other providers currently not implemented)
88+
89+
![azure AD configuration](docs/assets/aad-app-config.png)
90+
91+
Save all and publish your app. This allows you to use the user claim in you app like:
6592

6693
```csharp
6794
[Authorize]
@@ -75,6 +102,20 @@ public string UserName()
75102
}
76103
```
77104

105+
### Local Debugging
106+
107+
> Information: for this step it is required to have an configured app service!
108+
109+
This library give you an easy way to do local debugging enabled while your app is 100% cloud native. To do this you must only do a request to the following azure url:
110+
111+
`https://yourAzureAppServiceUrl/.auth/me`
112+
113+
The result of the request is a json with the authentication information of your current user. Put this json simply in the file `wwwroot/.auth/me.json`, and you are these user in your next debugging session. You also don't need a connection to the internet.
114+
115+
> Important: You must enable `UseStaticFiles` in your `Startup`. This is the case in the default ASP.NET frontend project.
116+
117+
## Details of the implementation
118+
78119
### Adding custom roles
79120

80121
If you want to add roles to the `User` property you can have a look in `Transformers/ClaimsTransformer.cs` in the Sample project. There you can see an example how to get started with this.
@@ -85,7 +126,7 @@ You can use the default behavior of asp.net core to configure EasyAuth. You must
85126

86127
> To get the property `this.Configuration` in your `Startup.cs` you must add `IConfiguration configuration` to your constructor parameters and create a property.
87128
88-
To configure you providers you simple add the following to your appsettings.json. (or to your environment variables, or other [configuration sources](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/).)
129+
To configure you providers you simple add the following to your `appsettings.json`. (or to your environment variables, or other [configuration sources](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/).)
89130

90131
```json
91132
"easyAuthOptions": {
@@ -112,7 +153,7 @@ Here are some notes to the JSON above:
112153
- each provider is disabled by default so you must enabled it
113154
- you can create own providers but there must implement `IEasyAuthAuthentificationService`. But you must also activate them here. (Don't put them in the DI. This package will do this by it's own.)
114155
- The `ProviderName` is the class name of the provider. that must be unique in your application.
115-
- The xClaimType property only define the property in the token that provide the requiered informations. Internaly that will always mapped to **name** and **role** claims.
156+
- The xClaimType property only define the property in the token that provide the required information. Internally that will always mapped to **name** and **role** claims.
116157

117158
> A list of all providers can be found in the headline `Auth Provider`
118159
@@ -125,8 +166,6 @@ You can provide additional options for the middleware:
125166
```csharp
126167
).AddEasyAuth(
127168
options => {
128-
// Override the auth endpoint
129-
options.AuthEndpoint = ClaimTypes.Email;
130169
// Add the EasyAuthForApplicationService auth provider and enabled it. Also Change the NameClaimType
131170
options.AddProviderOptions(new ProviderOptions("EasyAuthForApplicationsService"){Enabled = true, NameClaimType = "Test"})
132171
}
@@ -135,47 +174,82 @@ You can provide additional options for the middleware:
135174

136175
The `NameClaimType` is the ClaimType of the value which one will be used to fill the `User.Identity.Name` field.
137176

138-
#### Local Debugging
177+
#### Local Debugging advance
139178

140179
For debugging your application you can place a `me.json` in the `wwwroot/.auth` folder of your web app and add some configuration to the `AddEasyAuth` call.
141180
For example:
142181

143-
```csharp
144-
).AddEasyAuth(
145-
options =>
146-
{
147-
if (this.Environment.IsDevelopment())
148-
{
149-
options.AuthEndpoint = ".auth/me.json";
150-
}
151-
}
152-
);
182+
```json
183+
"localProviderOption": {
184+
"AuthEndpoint": ".auth/me.json",
185+
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
186+
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
187+
}
153188
```
154189

190+
This provider automatically deactivate it self in azure, to avoid anonymous access!
191+
155192
> **Info**: You can obtain the content for this file from an Azure Web App with EasyAuth configured by requesting the `/.auth/me` endpoint.
156193
157194
> **Info**: Make sure you added static file handling to your pipeline by adding `app.UseStaticFiles();` to your `public void Configure` method in the `Startup.cs`, e.g. just after `app.UseHttpsRedirection();` entry. Otherwise the static file can not be found at runtime.
158195
159-
> **Info**: Using a wwwroot sub-folder name that starts with `'.'`, like the suggested `.auth` folder name, is useful for content relevant only for localhost debugging as these are treated as hidden folders and are not included in publish output.
196+
> **Info**: Using a `wwwroot` sub-folder name that starts with `'.'`, like the suggested `.auth` folder name, is useful for content relevant only for localhost debugging as these are treated as hidden folders and are not included in publish output.
160197
161198
## Auth Provider
162199

163200
There are some predefined providers in this package. If you need your own or want contribute to our existing providers you must implement the `IEasyAuthAuthentificationService`.
164201

165-
### `EasyAuthWithAuthMeService`
202+
All providers can be configured with the following section in the `appsettings.json`
203+
204+
```json
205+
"easyAuthOptions": {
206+
"providerOptions": [
207+
{
208+
"ProviderName": "EasyAuthForAuthorizationTokenService", // type name of the provider
209+
"Enabled": true,
210+
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/spn", // optional
211+
"RoleClaimType": "roles" // optional
212+
},
213+
{
214+
"ProviderName": "EasyAuthWithHeaderService", // type name of the provider
215+
"Enabled": true,
216+
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", //optional
217+
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" //optional
218+
}
219+
],
220+
// the following is optional
221+
"localProviderOption": {
222+
"AuthEndpoint": ".auth/me",
223+
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
224+
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
225+
}
226+
}
227+
```
228+
229+
### `LocalAuthMeService`
166230

167-
This is a slightly special provider. This provider cannot be configured. You can only turn it on or off. It also does **not** implement the 'IEasyAuthAuthentificationService'. This provider is for development.
168-
It automatic disable it selfes, if you has configured azure easy auth feature.
169-
A developer can create a JSON with the content of the `/.auth/me` endpoint of an EasyAuth Azure Web App. So you don't need a connection to the internet or azure for development and just use your local things.
170-
You must only configure an Azure Web App with Authentification and browse the path:
231+
This is a slightly special provider. It does **not** implement the 'IEasyAuthAuthentificationService'. This provider is for development only!
232+
It automatic disable it self, if you has configured azure easy auth feature.
233+
A developer can create a JSON with the content of the `/.auth/me` endpoint of an EasyAuth protected Azure Web App. So you don't need a connection to the internet or azure for development and just use your local things.
234+
You must only configure an Azure Web App with Authentication and browse the path:
171235

172236
`https://hostnameOfYourWebSite/.auth/me`
173237

174-
This endpoint return a json after the authentication. Put the content in a new file in your `wwwroot`folder. (create the same path like: `.auth/me.json`)
238+
This endpoint returns a json after the authentication. Put the content in a new file in your `wwwroot` folder. (for example create a path like in the `wwwroot` folder: `.auth/me.json`)
239+
240+
If you must customize the settings of that provider you can add the section `localProviderOption` to your `appsettings.json`:
241+
242+
```json
243+
"localProviderOption": {
244+
"AuthEndpoint": ".auth/me",
245+
"NameClaimType": "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
246+
"RoleClaimType": "http://schemas.microsoft.com/ws/2008/06/identity/claims/role"
247+
}
248+
```
175249

176250
### `EasyAuthForAuthorizationTokenService`
177251

178-
Use this provider if you have a Azure Web App, that is not only be used by humans. For instance if you want to access your app with a Service Principal (SPN).
252+
Use this provider if you have a Azure Web App, that is not only be used by humans. For instance if you want to access your app with a Service Principal (SPN).
179253

180254
To create a Service Principal (SPN), which get access to your EasyAuth protected Application. You have to change the app manifest for you application in your Azure AD. Thanks to [Suzuko123](https://github.com/Suzuko123) for the following sample:
181255

@@ -205,7 +279,7 @@ This is the most common auth provider. You can use it to work with Azure Active
205279
## Authors
206280

207281
- **Kirsten Kluge** - _Initial work_ - [kirkone](https://github.com/kirkone)
208-
- **paule96** - _Refactoring / implementing the new stuff_ - [paule96](https://github.com/paule96)
282+
- **paule96** - _Refactoring / implementing the new stuff_ - [paule96](https://github.com/paule96)
209283
- **Christoph Sonntag** - _Made things even more uber_ - [Compufreak345](https://github.com/Compufreak345)
210284
- **myusrn** - _Dropped some knowledge about making IsInRoles work_ - [myusrn](https://github.com/myusrn)
211285
- **Suzuko123** - _Dropped some knowledge about Service Principals with easy auth_ - [Suzuko123](https://github.com/Suzuko123)

docs/assets/aad-app-config.png

697 KB
Loading

docs/assets/easyauth-config.png

1020 KB
Loading

0 commit comments

Comments
 (0)