ASP.NET (OWIN) Storing Tokens

Sample Project

Download this sample project configured with your Auth0 API Keys.

The Auth0 OAuth2 middleware will automatically add the id_token and access_token as claims on the ClaimsIdentity.

This means that inside any of your controllers you can simply cast the User.Identity property to a ClaimsIdentity, and then find the particular claim by querying the Claims property.

The sample code below shows how you can extract the claims for the access_token and id_token respectively:

var claimsIdentity = User.Identity as ClaimsIdentity;

// Extract tokens
string accessToken = claimsIdentity?.Claims.FirstOrDefault(c => c.Type == "access_token")?.Value;
string idToken = claimsIdentity?.Claims.FirstOrDefault(c => c.Type == "id_token")?.Value;
Previous Tutorial
3. Custom Login
Next Tutorial
5. User Profile
Use Auth0 for FREECreate free Account