# Forbidden: Insufficient scope, expected one of: read:users AND read:roles, OR read:role\_members

**URL:** <https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796>\
**Category:** Get Help\
**Tags:** api, rules, access-token, management-api, auth0\
**Created:** [June 8, 2022, 9:21am UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796 "2022-06-08T09:21:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kahina](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kahina/32/33596_2.png) [@kahina](https://community.auth0.com/u/kahina)\
**Post date:** [June 8, 2022, 9:21am UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796/1 "2022-06-08T09:21:22Z")

</div>

Hello,  
I’m working on a rule used to add roles to the access token via management API. Before that I get the user roles (as I need them to check the existing roles)  
Here is what I’m doing:

```auto
    const ManagementClient = require('auth0@2.35.0').ManagementClient;

    const management = new ManagementClient({
      token: auth0.accessToken,
      domain: auth0.domain
    });
    const rolesParams = { id: user.user_id };
    management.getUserRoles(rolesParams,function (err, user){
      if (err) {
        // Handle error.
        console.log(err);
      }
     console.log("success :::", user);
     callback(null, user, context);
    });
 ......

```

I got this error when executing this code:

> Forbidden: Insufficient scope, expected one of: read:users AND read:roles, OR read:role\_members

I checked the M2M permissions, they are all checked (including read:users, read:roles, read:role\_members)

when I tried to decode the token generated by _ **auth0.accessToken** _ , obviously, the scope does not include the required permissions

```auto
  "scopes": {
    "users": {
      "actions": [
        "read",
        "update"
      ]
    }
  }

```

Any help appreciated

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [June 8, 2022, 3:17pm UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796/2 "2022-06-08T15:17:47Z")

</div>

Hi @kahina

You need to do the client credentials grant in the rule, specifying your M2M client ID and secret, to get the access token with needed permissions.

Then you need to cache that, so you are not getting a new token on every login.

John

---

<div class="post-metadata">

**Author:** ![kahina](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kahina/32/33596_2.png) [@kahina](https://community.auth0.com/u/kahina)\
**Post date:** [June 9, 2022, 12:14pm UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796/3 "2022-06-09T12:14:21Z")

</div>

Hi @John,  
Thanks a lot for your response, it works.

If another person met the same problem and couldn’t find a way, here is a topic that will help for sure

> [@How do I get an access token to call Management API v2 from a rule?](https://community.auth0.com/t/how-do-i-get-an-access-token-to-call-management-api-v2-from-a-rule/5970/2):
>
> The rule execution context will behave like any other non-interactive client, having to get an access token using the [client credentials grant](https://auth0.com/docs/api-auth/config/asking-for-access-tokens). First, you will have to [create a non-interactive client and authorize it to access Management API v2](https://auth0.com/docs/api/management/v2/tokens#1-create-and-authorize-a-client). Choose the required scopes, and name it in a meaningful way, like “Management API v2 client for rules”. Then, configure the following [settings for rules](https://manage.auth0.com/#/rules): AUTH0\_DOMAIN: your Auth0 domain, like contoso.auth0.com. APIV2\_CLIENT\_ID: the id of the non-in…

Kahina,

---

<div class="post-metadata">

**Author:** ![john.gateley](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/john.gateley/32/10879_2.png) [@john.gateley](https://community.auth0.com/u/john.gateley)\
**Post date:** [June 9, 2022, 1:24pm UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796/4 "2022-06-09T13:24:26Z")

</div>

Thanks for the additional docs! – j

---

<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:** [July 28, 2022, 1:10pm UTC](https://community.auth0.com/t/forbidden-insufficient-scope-expected-one-of-read-users-and-read-roles-or-read-role-members/84796/5 "2022-07-28T13:10:57Z")

</div>


