ASP.NET (OWIN) Storing Tokens

Seed Project

Download a sample project. You will need to login for the sample to be preconfigured.

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
Try Auth0 for FREECreate free Account