# Add roles to access token

**URL:** <https://community.auth0.com/t/add-roles-to-access-token/76471>\
**Category:** Get Help\
**Tags:** rules, access-token, auth0, roles\
**Created:** [January 15, 2022, 6:00pm UTC](https://community.auth0.com/t/add-roles-to-access-token/76471 "2022-01-15T18:00:59Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![giovannilaperna](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/giovannilaperna/32/34414_2.png) [@giovannilaperna](https://community.auth0.com/u/giovannilaperna)\
**Post date:** [January 16, 2022, 5:09am UTC](https://community.auth0.com/t/add-roles-to-access-token/76471/2 "2022-01-16T05:09:03Z")

</div>

Thanks to [this](https://community.auth0.com/t/add-authorization-core-role-to-user-object/65071/8) topic I found the solution:

```auto
function (user, context, callback) {
    // This rule adds the authenticated user's roles to the access token.

  var namespace = 'https://my-domain.com/';
  context.accessToken[namespace + 'roles'] = context.authorization.roles;
  callback(null, user, context);
}

```

---

_[View the full topic](https://community.auth0.com/t/add-roles-to-access-token/76471)._
