# Can't use rule to include user role in id token

**URL:** <https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460>\
**Category:** Get Help\
**Created:** [November 19, 2021, 5:15pm UTC](https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460 "2021-11-19T17:15:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/clin/32/13280_2.png) [@clin](https://community.auth0.com/u/clin)\
**Post date:** [November 19, 2021, 5:15pm UTC](https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460/1 "2021-11-19T17:15:39Z")

</div>

Hi, I’m trying to return user role as part of the IdToken custom claim. According to the documentation I tried to use one of the template RULE, Add user roles from a SQL Server database. And when I tried to log in and get id token, I got this error:

The “config.server” property is required and must be of type string.

which seems out of my control? Can you suggest a way to fix it?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 19, 2021, 7:30pm UTC](https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460/2 "2021-11-19T19:30:24Z")

</div>

Hi @clin,

Welcome to the Auth0 Community!

I understand that you are trying to use a Rule to add the user’s role in the ID Token.

First, I believe that the _Add user roles from a SQL Server database_ is not the Rule you are looking for to add user roles to the ID Token.

Instead, you’ll need to use the [Add user roles to tokens rule](https://auth0.com/docs/authorization/authorization-policies/sample-use-cases-rules-with-authorization#add-user-roles-to-tokens) to accomplish your preferred use case.

For convenience, the code snippet is:

```auto
function (user, context, callback) {
  const namespace = 'http://demozero.net';
  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);
}

```

Please let me know if there’s anything else I can do to help.

Thank you.

---

<div class="post-metadata">

**Author:** ![clin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/clin/32/13280_2.png) [@clin](https://community.auth0.com/u/clin)\
**Post date:** [November 19, 2021, 7:43pm UTC](https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460/4 "2021-11-19T19:43:12Z")

</div>

Ok thanks for the quick reply, I tried the snippet and it works. But I only see the roles in id token is there a way to include also the organizations that the user belongs to and the corresponding permission info in the id token too? Thanks

---

<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:** [December 4, 2021, 7:43pm UTC](https://community.auth0.com/t/cant-use-rule-to-include-user-role-in-id-token/73460/5 "2021-12-04T19:43:43Z")

</div>

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