I'm using ASP.net Core MVC. In the login process, in a POST controller action, I am using HttpContext.SignInAsync with an AuthenticationProperties that contains a JWT access token. In the same HttpRequest, I cannot refetch those properties to get the access token that was created.
...
var claimsPrincipal = CreateClaimsPrincipal("userName");
var accessToken = new AuthenticationToken()
{
Name = OpenIdConnectParameterNames.AccessToken,
Value = TOKEN_VALUE
};
AuthenticationToken[] tokens = { accessToken };
var authenticationProperties = new AuthenticationProperties();
authenticationProperties.StoreTokens(tokens);
authenticationProperties.IsPersistent = true;
// Here we sign in the user
await HttpContext.SignInAsync(claimsPrincipal, authenticationProperties);
// Afterwards, we cannot access the access token either from
var tokenValueFromGetTokenAsync = HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken)
// Or with
var result = await HttpContext.AuthenticateAsync();
var tokenValueFromAuthenticateAsync = result.Properties.GetTokenValue(OpenIdConnectParameterNames.AccessToken);
Is there a way to set the AuthenticationProperties of the current http request ? I know I can set the ClaimsPrincipal with
HttpContext.user = claimsPrincipal
But is there something similar that I can do with AuthenticationProperties. Something like
// I made that part up, would be cool though
HttpContext.Authentication.Properties = authenticationProperties
I uploaded a super simple code example of this to github:
check the SecurityController Login method decorated with a HttpPost attribute.