Auth0 Home Blog Docs

HttpContext.GetTokenAsync("access_token") is null

access-token

#1

I’m using the sample code from the ‘ASP.NET Core Storing Tokens’ quickstart. I can login successfully, but when I interrogate the HttpContext.GetTokenAsync(“access_token”) , it says it is null and does not exist in httpcontext. What are the steps I need to perform to get the access token to be returned in the httpcontext.


#2

If you are using OpenIdConnect the tokens will only be saved to the context if
SaveTokens = true; in the startup

.AddOpenIdConnectAuthentication(options => {
   // other options..
    options.SaveTokens = true;
});

#3

Thanks for the response. I can’t see AddOpenIdConnectAuthentication. I am using .AddOpenIdConnect(“Auth0”, options =>
{
// other options
SaveToken = true;
}
I am using the sample from the quickatart. I only added the values from my client and changed nothing from the code and it does not work. So I’m thinking I’ve not configured my client correctly.


#4

This doc is specific regard the storage of access tokens:
https://auth0.com/docs/quickstart/webapp/aspnet-core/v2/02-storing-tokens
Must some other config if this doesn’t work?


#5

Thats the doc I followed. I’m assuming there’s something wrong with the config of my client.


#6