# Assign roles to m2m clients

**URL:** <https://community.auth0.com/t/assign-roles-to-m2m-clients/53510>\
**Category:** Get Help\
**Created:** [November 19, 2020, 11:33am UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510 "2020-11-19T11:33:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyndon.fawcett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lyndon.fawcett/32/18797_2.png) [@lyndon.fawcett](https://community.auth0.com/u/lyndon.fawcett)\
**Post date:** [November 19, 2020, 11:33am UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/1 "2020-11-19T11:33:36Z")

</div>

Hi, from the UI I can see it’s possible to assign permissions to m2m clients.

However, I cannot seem to assign roles (as far as I can see). Is there a way to associate a role to a m2m client?

There seems to be another other threads asking this question, but no public or documented answer:

> [@Adding role to client-credential grant](https://community.auth0.com/t/adding-role-to-client-credential-grant/12665/3):
>
> Hey there! Terribly sorry for such delay in response! We’re doing our best in providing the best developer support experience out there, but sometimes our bandwidth is just not enough for all the questions that are coming in. Sorry for the inconvenience! Do you still require further assistance from us?

---

<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:** [November 19, 2020, 2:45pm UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/2 "2020-11-19T14:45:28Z")

</div>

Hi @lyndon.fawcett

I don’t think there is an easy way to do this. What is the use case?

John

---

<div class="post-metadata">

**Author:** ![lyndon.fawcett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lyndon.fawcett/32/18797_2.png) [@lyndon.fawcett](https://community.auth0.com/u/lyndon.fawcett)\
**Post date:** [November 19, 2020, 4:05pm UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/3 "2020-11-19T16:05:40Z")

</div>

Hi @john.gateley, thanks for the reply.

My use case is that I have a single API Gateway which is accessed by both human users and machines.

Both humans and machines need to have restricted access to the endpoints **and** resources that they need to access. I was planning on using a combination of Roles and Permissions to achieve this but noticed that they are only available for users.

I’m trying to support multi-tenancy within my application.

I was thinking that I could have generic permissions for the application (read:config, write:config) and then use the role name to capture the tenant context e.g. a role name: tenant1\_config\_admin.

I don’t want to have to resign in for each tenant, I want the user to be able to seamlessly swap between tenants without getting a new token.

Reading [Multi-Tenant Applications Best Practices](https://auth0.com/docs/best-practices/multi-tenant-apps-best-practices) it suggests that for my use case to use app\_metadata to achieve this, however that means that the scopes defined in Auth0 work across all tenants for a single user, which is not desired. For example, a user may be an admin in one tenant and only a user in another.

Heres example output of an access token payload on the above:

```auto
scopes: "config:r areas:rw"
permissions: [
   "config:r",
   "areas:rw"
],
tenants: [
   tenant1,
   tenant2
] 

```

The only solution that I can see to this is by putting everything, both tenants and roles/permissions in the app\_metadata and use rules and hooks to put this into the access token. This works but feels clunky. Also, the client\_metadata for m2m seems limited to a key-value pair list, which limits how it can be used (not a json object which can easily define a struct with tenants: roles: and permissions, though can be built up in the hook)

Example output of the above in an access token:

```auto
scopes: ""
permissions: {}
tenants: [
   tenant1: [
     "config:r"
   ]
   tenant2: [
     "areas:rw"
   ]
]

```

Any further guidance on this use case would be greatly 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:** [November 24, 2020, 4:31pm UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/4 "2020-11-24T16:31:21Z")

</div>

Hi @lyndon.fawcett

This is complex. Multi-tenancy is complex. For this, I suggest our professional services.  
It requires some time to completely understand what you are trying to achieve, then architect the system.

John

---

<div class="post-metadata">

**Author:** ![lyndon.fawcett](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lyndon.fawcett/32/18797_2.png) [@lyndon.fawcett](https://community.auth0.com/u/lyndon.fawcett)\
**Post date:** [November 24, 2020, 4:35pm UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/5 "2020-11-24T16:35:24Z")

</div>

Hi @john.gateley ,

I suppose I was looking for an off the shelf answer for this use case. It’s good to be aware that there isn’t one. Thanks 👍

Lyndon

---

<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:** [December 8, 2020, 9:59am UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/6 "2020-12-08T09:59:23Z")

</div>

Sometimes it’s just not that obvious Lyndon but we’re happy to help!

---

<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:** [December 8, 2020, 9:59am UTC](https://community.auth0.com/t/assign-roles-to-m2m-clients/53510/7 "2020-12-08T09:59:27Z")

</div>


