c# – 在ASP.NET Core 2.0中获取AuthenticationInfo
发布时间:2020-12-15 18:25:04 所属栏目:百科 来源:网络整理
导读:如何从ASP.NET Core 2.0中的HttpContext获取AuthenticationInfo属性.我理解,随着ASP.NET Core 2.0中安全性的重新设计,AuthenticationManager现在已经过时,我应该删除.Authentication. 我曾经在1.1.2中做过类似的事情 var info = await httpContext.Authentic
如何从ASP.NET Core 2.0中的HttpContext获取AuthenticationInfo属性.我理解,随着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); 解决方法
AuthenticationManager.GetAuthenticateInfoAsync(string)在2.0中被IAuthenticationService.AuthenticateAsync(string)取代:它现在返回AuthenticateResult,但它的工作方式完全相同.
您的代码段可以更新为: var result = await httpContext.AuthenticateAsync(); result.Properties.StoreTokens(new List<AuthenticationToken> { new AuthenticationToken { Name = OpenIdConnectParameterNames.AccessToken,Value = refreshToken } }); await httpContext.SignInAsync(result.Principal,result.Properties); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |