Adding additional claims to access_token (asp.net core 3.1 mvc)

Thanks @andy.carter! That’s perfect!

For anybody else interested, if you apply the rule in Andy’s reply, this is what the access token then looks like:

{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "Oh3auIcHF7FKoi_maBqKe"
}.{
  "https://blah.namespace.com/email": "test@contoso.com",
  "iss": "https://blah.au.auth0.com/",
  "sub": "auth0|5ebb0ff83873a20be682a54b",
  "aud": [
    "https://api.blah.net",
    "https://blah.au.auth0.com/userinfo"
  ],
  "iat": 1590089834,
  "exp": 1590176234,
  "azp": "2wDvZX5y1vXRj70U37hIzezV2IPDqgbt",
  "scope": "openid profile"
}.[Signature]

In the API, you can then extract the email with the following code:

var email = User.Claims.FirstOrDefault(c => c.Type == "https://blah.namespace.com/email").Value;

Cheers!

1 Like