AuthenticationManager.SignIn與AuthenticationManager.AuthenticateAsync的目的是什么? - What are the purposes of AuthenticationManager.Sig
AuthenticationManager
has two methods.
AuthenticationManager有兩種方法。
void SignIn(params ClaimsIdentity[] identities);
Task<AuthenticateResult> AuthenticateAsync(string authenticationType);
What are their purposes? In what situations should they each be used?
他們的目的是什么?在什么情況下應該使用它們?
2 个解决方案
#1
1
I think the purposes are described on the names of the methods Authenticate and SignIn
我認為目的是在方法Authenticate和SignIn的名稱上描述的
So the purpose of AuthenticateAsync is basically get an Authentication Ticket
因此,AuthenticateAsync的目的基本上是獲取身份驗證票證
await ticket
= Authentication.AuthenticateAsync(DefaultAuthenticationTypes.ExternalBearer);
it returns an AuthenticateResult like this
它返回一個像這樣的AuthenticateResult
{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;
}
最佳答案:
本文经用户投稿或网站收集转载,如有侵权请联系本站。
0条回复