How do I get the AuthenticationInfo
property from the HttpContext in ASP.NET Core 2.0. I understand that with the redesign of Security in ASP.NET Core 2.0 the AuthenticationManager
is now obsolete and that I should remove .Authentication
.
I used to do 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);
AuthenticationManager.GetAuthenticateInfoAsync(string)
was replaced by IAuthenticationService.AuthenticateAsync(string)
in 2.0: it now returns an AuthenticateResult
but it works exactly the 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);
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