ASP NET Multiple Authentication 1690214881
ASP NET Multiple Authentication 1690214881
ASP.NET:
Multiple
Authentication
Schemes
How we can validate multiple
tokens with different providers
Saeed Esmaeelinejad
in the API?
Core Authentication
Authentication Scheme
The authentication scheme can select which authentication handler is responsible for
generating the correct set of claims.
An authentication scheme is a name that corresponds to:
An authentication handler.
Options for configuring that specific instance of the handler.
The registered authentication handlers and their configuration options are called
"schemes".
Scenario
We have an API that supports authentication but the issue is, the access tokens may
come from different providers and the API should be able to validate all of them.
The tokens are generated by three providers:
1- IdentityServerA 2- IdentityServerB 3- Custom token (not JWT)
A simple implementation for one identity server (A)
In ASP.NET, authentication is handled by the
authentication service, IAuthenticationService,
which is used by authentication middleware. The
authentication service uses registered
authentication handlers to complete
authentication-related actions.
System.InvalidOperationException: 'Scheme
already exists: Bearer'
If you check the previous page again, you see this option in the AddAuthetication:
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
You made it :)
Thanks for reading :)
Saeed Esmaeelinejad