Understanding the elements of authentication in .NET 5
Authentication in ASP.NET Core is handled by authentication middleware, which uses registered authentication handlers to perform authentication. Registered authentication handlers and their associated configurations are called authentication schemes.
The following are the core elements of an authentication framework:
- Authentication scheme: This defines the type and behavior of the authentication to be used to authenticate, challenge, and forbid. Authentication schemes are registered as authentication services in the
Startup.ConfigureServices
method. They comprise an authentication handler and have options to configure this handler. You can register multiple authentication schemes to authenticate, challenge, and forbid actions, or specify authentication schemes in authorization policies you configure. The following is some sample code to register anOpenIdConnect
authentication scheme:services.AddAuthentication(OpenIdConnectDefaults...