如何AuthenticationInfo从ASP.NET Core 2.0中的HttpContext 获取属性.我理解,随着ASP.NET Core 2.0中安全性的重新设计,AuthenticationManager现在已经过时,我应该删除.Authentication.
我曾经在1.1.2中做过类似的事情
var info = await httpContext.Authentication.GetAuthenticateInfoAsync("Automatic");
info.Properties.StoreTokens(new List<AuthenticationToken>
{
new AuthenticationToken
{
Name = OpenIdConnectParameterNames.AccessToken,
Value = accessToken
},
new AuthenticationToken
{
Name = OpenIdConnectParameterNames.RefreshToken,
Value = refreshToken
}
});
await httpContext.Authentication.SignInAsync("Automatic", info.Principal, info.Properties);
Run Code Online (Sandbox Code Playgroud)
Kév*_*let 24
AuthenticationManager.GetAuthenticateInfoAsync(string)被IAuthenticationService.AuthenticateAsync(string)2.0 取代:它现在返回一个AuthenticateResult但它的工作方式完全相同.
您的代码段可以更新为:
var result = await httpContext.AuthenticateAsync();
result.Properties.StoreTokens(new List<AuthenticationToken>
{
new AuthenticationToken
{
Name = OpenIdConnectParameterNames.AccessToken,
Value = accessToken
},
new AuthenticationToken
{
Name = OpenIdConnectParameterNames.RefreshToken,
Value = refreshToken
}
});
await httpContext.SignInAsync(result.Principal, result.Properties);
Run Code Online (Sandbox Code Playgroud)