What are the goals of AuthenticationManager.SignIn vs AuthenticationManager.AuthenticateAsync?

AuthenticationManager has two methods.

 void SignIn(params ClaimsIdentity[] identities); Task<AuthenticateResult> AuthenticateAsync(string authenticationType); 

What are their goals? In what situations should they be used?

+5
source share
2 answers

I think the goals are described in the names of the Authentication and SignIn methods

So the goal of AuthenticateAsync is to get an authentication ticket

 await ticket = Authentication.AuthenticateAsync(DefaultAuthenticationTypes.ExternalBearer); 

it returns an AuthenticateResult similar to this

 {Microsoft.Owin.Security.AuthenticateResult} Description: {Microsoft.Owin.Security.AuthenticationDescription} Identity: {System.Security.Claims.ClaimsIdentity} Properties: {Microsoft.Owin.Security.AuthenticationProperties} 

and with this result you can now SignIn (add Identity information to the context)

 Context.Authentication.SignIn(ticket.Properties, ticket.Identity); 

You can see this very clearly in the code example below.

 var ticket = await Context.Authentication.AuthenticateAsync(Options.AuthenticationType); if(ticket != null) { Context.Authentication.SignIn(ticket.Properties, ticket.Identity); Response.Redirect(ticket.Properties.RedirectUri); return true; } 
0
source

Here is a description of these two methods based on the visual studio dashboard. This may be helpful.

AuthenticationManager.SignIn AuthenticationManager.AuthenticateAsync

0
source

Source: https://habr.com/ru/post/1271933/


All Articles