auth0 / auth0-aspnet-owin

Auth0 ASP.NET 4.5 Owin/Katana Authentication Handler
MIT License
46 stars 50 forks source link

Custom claims #61

Closed Robar666 closed 6 years ago

Robar666 commented 6 years ago

I created a rule in Auth0 to add custom claims.

function (user, context, callback) {
  const namespace = 'https://yada.com/';
  context.idToken[namespace + 'yada_user_id'] = user.app_metadata.YadaUserId;
  callback(null, user, context);
}

If I debug during

Provider = new Auth0AuthenticationProvider {
  OnAuthenticated = context => {
    var tokenContainingCustomClaims = context.IdToken;
  }
}

and parse the JWT token on https://jwt.io/, I can see the custom claims.

But if I try to access them later via HttpContext.GetOwinContext().Authentication.User.Claims, I can only see the default claims, but not my custom claims.

Looking through the code I also couldn't find a LOC which would add custom claims. Is this a bug in auth0-aspnet-owin or do I have to parse the JWT token on my own?

jerriep commented 6 years ago

@Robar666 We are actually in the process of deprecating this library and will suggest users move over to using the built-in OWIN OpenID Connect middleware.

Here is a preliminary sample on how to use that particular middleware with Auth0: https://github.com/auth0/auth0-aspnet-owin/blob/owin4/test/Auth0OwinTest/Startup.cs

jerriep commented 6 years ago

Closing this as this library is now deprecated. Users should use the standard OWIN OIDC middleware as per https://auth0.com/docs/quickstart/webapp/aspnet-owin