ASP.NET Core middleware that enables an application to support the OpenID Connect authentication workflow. This package was built from the source code at https://github.com/dotnet/dotnet/tree/87bc0b04e21d786669142109a5128c95618b75ed
$ dotnet add package Microsoft.AspNetCore.Authentication.OpenIdConnectMicrosoft.AspNetCore.Authentication.OpenIdConnect provides middleware that enables an application to support the OpenID Connect authentication workflow.
To use Microsoft.AspNetCore.Authentication.OpenIdConnect, follow these steps:
dotnet add package Microsoft.AspNetCore.Authentication.OpenIdConnect
To configure Microsoft.AspNetCore.Authentication.OpenIdConnect, you need to add the necessary services and middleware to your application.
In the Program.cs of your ASP.NET Core app, add the following code to register the OpenID Connect authentication services:
builder.Services
.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddCookie()
.AddOpenIdConnect(options =>
{
// Configure the authentication options
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "your-identity-provider";
options.ClientId = "your-client-id";
options.ClientSecret = "your-client-secret-from-user-secrets-or-keyvault";
options.ResponseType = "code";
options.Scope.Add("profile");
options.SaveTokens = true;
});
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.
Add the following code to enable the OpenID Connect authentication middleware:
var app = builder.Build();
app.UseAuthentication();
This ensures that the authentication middleware is added to the request pipeline.
The main types provided by Microsoft.AspNetCore.Authentication.OpenIdConnect are:
OpenIdConnectOptions: Represents the options for configuring the OpenID Connect authentication middlewareOpenIdConnectEvents: Provides event handlers for various stages of the OpenID Connect authentication workflowFor more information on these types and their usage, refer to the official documentation.
For additional documentation on using OpenID Connect authentication in ASP.NET Core, you can refer to the following resources:
Microsoft.AspNetCore.Authentication.OpenIdConnect is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.