Get AuthenticationInfo in ASP.NET Core 2.0

How to get AuthenticationInfo property from HttpContext in ASP.NET Core 2.0. I understand that with the security redesign in ASP.NET Core 2.0, the AuthenticationManager now deprecated and that I have to remove .Authentication .

I used something like this in 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); 
+5
source share
1 answer

AuthenticationManager.GetAuthenticateInfoAsync(string) been replaced with IAuthenticationService.AuthenticateAsync(string) in 2.0: now it returns AuthenticateResult , but it works the exact same way.

Your snippet can be updated to:

 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); 
+13
source

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


All Articles