I am currently struggling with an Asp.net core 2 application which uses two openid providers for authentication, mapped to two different Authentication Schemes (with different names).
The problem I am facing is trying to logout of the specific scheme that is currently being used. For example, if I support both Google and Facebook authentication, I need to understand which scheme is currently being used, and call the SignOut
method indicating the correct scheme. This allows me to clear the local cookies and also redirect the user to the external identity provider and logout.
The thing is that I am not able to find a GetCurrentScheme()
sort of function so that I can use to then specify the scheme in the SignOut
method. I am sure I am missing something basic...
Authentication is the process of determining a user's identity. Authorization is the process of determining whether a user has access to a resource. In ASP.NET Core, authentication is handled by the authentication service, IAuthenticationService, which is used by authentication middleware.
This blog starts with authentication and authorization concepts and after that explains the three default important ways and three custom authentication ways for doing authentication and authorization i.e. windows, forms ,passport, multipass, JWT and SAML authentication.
An authentication scheme is a module that implements a way for a user to authenticate itself to SimpleID. In particular, an authentication scheme checks credentials presented by the user against some data store containing user information, and determines whether the credentials match those stored in the data store.
For an introduction to authentication schemes in ASP.NET Core, see Authentication scheme. In some scenarios, such as Single Page Applications (SPAs), it's common to use multiple authentication methods. For example, the app may use cookie-based authentication to log in and JWT bearer authentication for JavaScript requests.
Select the handler with which the app will authorize by passing a comma-delimited list of authentication schemes to [Authorize]. The [Authorize] attribute specifies the authentication scheme or schemes to use regardless of whether a default is configured. For example: ASP.NET Core 2.x.
Authentication policy schemes make it: Easy to forward any authentication action to another scheme. Forward dynamically based on the request. All authentication schemes that use derived AuthenticationSchemeOptions and the associated AuthenticationHandler<TOptions>: Are automatically policy schemes in ASP.NET Core 2.1 and later.
Authentication middleware is responsible for authentication in ASP.Net Core applications. The authentication middleware uses the registered authentication handlers to authenticate a user. The registered handlers and their associated configurations are called schemes.
I had the same question, but I finally put the authentication scheme in the claims collection in my SignIn
method :
claims.Add(new Claim(ClaimTypes.AuthenticationMethod, authenticationScheme));
So, in the SignOut
method, I can retrieve the authentication scheme :
var authenticationScheme = HttpContext.User.FindFirstValue(ClaimTypes.AuthenticationMethod);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With