|
| 1 | +## About |
| 2 | + |
| 3 | +`Microsoft.AspNetCore.Authentication.OpenIdConnect` provides middleware that enables an application to support the OpenID Connect authentication workflow. |
| 4 | + |
| 5 | +## Key Features |
| 6 | + |
| 7 | +* Single sign-on and single sign-out support |
| 8 | +* Integration with external identity providers |
| 9 | +* Token validation and management |
| 10 | +* Configuration and mapping of user claims |
| 11 | + |
| 12 | +## How to Use |
| 13 | + |
| 14 | +To use `Microsoft.AspNetCore.Authentication.OpenIdConnect`, follow these steps: |
| 15 | + |
| 16 | +### Installation |
| 17 | + |
| 18 | +```shell |
| 19 | +dotnet add package Microsoft.AspNetCore.Authentication.OpenIdConnect |
| 20 | +``` |
| 21 | + |
| 22 | +### Configuration |
| 23 | + |
| 24 | +To configure `Microsoft.AspNetCore.Authentication.OpenIdConnect`, you need to add the necessary services and middleware to your application. |
| 25 | + |
| 26 | +1. In the `Program.cs` of your ASP.NET Core app, add the following code to register the OpenID Connect authentication services: |
| 27 | + ```csharp |
| 28 | + builder.Services |
| 29 | + .AddAuthentication(options => |
| 30 | + { |
| 31 | + options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; |
| 32 | + options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; |
| 33 | + }) |
| 34 | + .AddCookie() |
| 35 | + .AddOpenIdConnect(options => |
| 36 | + { |
| 37 | + // Configure the authentication options |
| 38 | + options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; |
| 39 | + options.Authority = "your-identity-provider"; |
| 40 | + options.ClientId = "your-client-id"; |
| 41 | + options.ClientSecret = "your-client-secret-from-user-secrets-or-keyvault"; |
| 42 | + options.ResponseType = "code"; |
| 43 | + options.Scope.Add("profile"); |
| 44 | + options.SaveTokens = true; |
| 45 | + }); |
| 46 | + ``` |
| 47 | + |
| 48 | + Make sure to replace `your-identity-provider`, `your-client-id`, and `your-client-secret-from-user-secrets-or-keyvault`, with the appropriate values for your application and identity provider. |
| 49 | + |
| 50 | +2. Add the following code to enable the OpenID Connect authentication middleware: |
| 51 | + ```csharp |
| 52 | + var app = builder.Build(); |
| 53 | + |
| 54 | + app.UseAuthentication(); |
| 55 | + ``` |
| 56 | + This ensures that the authentication middleware is added to the request pipeline. |
| 57 | + |
| 58 | +## Main Types |
| 59 | + |
| 60 | +The main types provided by `Microsoft.AspNetCore.Authentication.OpenIdConnect` are: |
| 61 | + |
| 62 | +* `OpenIdConnectOptions`: Represents the options for configuring the OpenID Connect authentication middleware |
| 63 | +* `OpenIdConnectEvents`: Provides event handlers for various stages of the OpenID Connect authentication workflow |
| 64 | + |
| 65 | +For more information on these types and their usage, refer to the [official documentation](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.authentication.openidconnect). |
| 66 | +
|
| 67 | +## Additional Documentation |
| 68 | + |
| 69 | +For additional documentation on using OpenID Connect authentication in ASP.NET Core, you can refer to the following resources: |
| 70 | + |
| 71 | +* [ASP.NET Core Authentication](https://learn.microsoft.com/aspnet/core/security/authentication) |
| 72 | +* [OpenID Connect](https://openid.net/developers/how-connect-works) |
| 73 | +* [Entra ID documentation](https://learn.microsoft.com/entra/identity) |
| 74 | +
|
| 75 | +## Feedback & Contributing |
| 76 | + |
| 77 | +`Microsoft.AspNetCore.Authentication.OpenIdConnect` is released as open-source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/aspnetcore). |
0 commit comments