# Extract roles from authentication token in login callback

**URL:** <https://community.auth0.com/t/extract-roles-from-authentication-token-in-login-callback/37100>\
**Category:** Get Help\
**Created:** [January 30, 2020, 2:57pm UTC](https://community.auth0.com/t/extract-roles-from-authentication-token-in-login-callback/37100 "2020-01-30T14:57:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raffaelesgarro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raffaelesgarro/32/13366_2.png) [@raffaelesgarro](https://community.auth0.com/u/raffaelesgarro)\
**Post date:** [January 30, 2020, 2:57pm UTC](https://community.auth0.com/t/extract-roles-from-authentication-token-in-login-callback/37100/1 "2020-01-30T14:57:52Z")

</div>

I have a Spring (boot) application that uses Auth0 for authentication. I fire the authentication flow in my controller with the Auth0 SDK:

```auto
// controller is com.auth0.AuthenticationController
controller.buildAuthorizeUrl(req, response, selfUrl + "/auth0/on-after-login")
                .withScope("openid profile email")
                .build();

```

but the token that I receive in the callback does not contains the claim `https://access.control/roles` that the sample app uses to read user’s roles. I have the following questions:

- Is the `https://access.control/roles` claim somewhat standard to get user roles?
- If yes, why is it empty in all of my tokens?

---

<div class="post-metadata">

**Author:** ![raffaelesgarro](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/raffaelesgarro/32/13366_2.png) [@raffaelesgarro](https://community.auth0.com/u/raffaelesgarro)\
**Post date:** [January 30, 2020, 11:06pm UTC](https://community.auth0.com/t/extract-roles-from-authentication-token-in-login-callback/37100/2 "2020-01-30T23:06:04Z")

</div>

Meh, this community doesn’t work well for getting support. Anyway, I solved it by myself using this custom rule:

```auto
function (user, context, callback) {
  // https://auth0.com/docs/authorization/concepts/sample-use-cases-rules#add-user-roles-to-tokens
  const namespace = 'https://access.control';
  const assignedRoles = (context.authorization || {}).roles;

  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};

  idTokenClaims[`${namespace}/roles`] = assignedRoles;
  accessTokenClaims[`${namespace}/roles`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;

  callback(null, user, context);
}

```

from [this page](https://auth0.com/docs/authorization/concepts/sample-use-cases-rules#add-user-roles-to-tokens).

I think the rule should at least be mentioned in the relevant examples like [this one](https://github.com/auth0-samples/auth0-spring-security-mvc-sample/issues/43).

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [February 14, 2020, 11:06pm UTC](https://community.auth0.com/t/extract-roles-from-authentication-token-in-login-callback/37100/3 "2020-02-14T23:06:09Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
