# Injecting permissions into JWT token using Auth0 rules

**URL:** <https://community.auth0.com/t/injecting-permissions-into-jwt-token-using-auth0-rules/38817>\
**Category:** Get Help\
**Tags:** jwt, rules, auth0-rules\
**Created:** [March 3, 2020, 5:56pm UTC](https://community.auth0.com/t/injecting-permissions-into-jwt-token-using-auth0-rules/38817 "2020-03-03T17:56:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![herry](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@herry](https://community.auth0.com/u/herry)\
**Post date:** [March 3, 2020, 5:56pm UTC](https://community.auth0.com/t/injecting-permissions-into-jwt-token-using-auth0-rules/38817/1 "2020-03-03T17:56:14Z")

</div>

Hi,

I want to inject permissions into the user’s JWT token where the permissions is obtained from a public authorisation API. I tried to use the following rule but failed:

```
function (user, context, callback) {
  const url = require("url");
  const request = require("request");
  const authURL = new url.URL("https://some-domain.com/get_permissions");
  
  authURL.searchParams.append("email", user.email);
  return request(authURL.toString(), function(error, response, body) {
    if (!error && response.statusCode === 200) {
      const permissions = JSON.parse(body);
      context.accessToken.permissions = permissions;
    }
    return callback(null, user, context);
  });
}

```

I got the following JWT token:

```
{
  "iss": "https://test.eu.auth0.com/",
  "aud": [
    "https://test.eu.auth0.com/userinfo"
  ],
  "permissions": []
}

```

Is there any suggestion on how to accomplish my goal?

Regards,  
Herry

---

<div class="post-metadata">

**Author:** ![colin.coutts](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/colin.coutts/32/17217_2.png) [@colin.coutts](https://community.auth0.com/u/colin.coutts)\
**Post date:** [March 3, 2020, 11:31pm UTC](https://community.auth0.com/t/injecting-permissions-into-jwt-token-using-auth0-rules/38817/2 "2020-03-03T23:31:40Z")

</div>

Hi @herry and welcome to the Auth0 Community! 🙂

I’d recommend exploring our documentation on adding [custom claims](https://auth0.com/docs/tokens/concepts/jwt-claims?_ga=2.175153826.1847852267.1583165976-433006610.1582572173) to your JWT. This [documentation](https://auth0.com/docs/scopes/current/sample-use-cases#request-custom-api-access) also contains some use cases that involve requesting custom API access as well as further context around adding your permissions or scopes to a JWT.

Let me know if that information helps move your solution forward.

Best Regards,  
Colin

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 8, 2024, 8:23am UTC](https://community.auth0.com/t/injecting-permissions-into-jwt-token-using-auth0-rules/38817/3 "2024-01-08T08:23:53Z")

</div>

Hey there!

As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon, I’m excited to let you know about our next [Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043) on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!

[Learn more here!](https://community.auth0.com/t/auth0-community-ask-me-anything-rules-hooks-and-why-actions-matter/124043)
