AuthenticationManager
has two methods.
void SignIn(params ClaimsIdentity[] identities);
Task<AuthenticateResult> AuthenticateAsync(string authenticationType);
What are their purposes? In what situations should they each be used?
I think the purposes are described on the names of the methods Authenticate and SignIn
So the purpose of AuthenticateAsync is basically get an Authentication Ticket
await ticket
= Authentication.AuthenticateAsync(DefaultAuthenticationTypes.ExternalBearer);
it returns an AuthenticateResult like 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 the Identity information to the context)
Context.Authentication.SignIn(ticket.Properties, ticket.Identity);
You can see it very clearly in the sample code 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;
}
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