# Automatically assign roles to federated OIDC users

**URL:** <https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217>\
**Category:** Get Help\
**Tags:** federation, oidc, rbac, roles\
**Created:** [August 4, 2022, 6:54pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217 "2022-08-04T18:54:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![k01157](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/k01157/32/39147_2.png) [@k01157](https://community.auth0.com/u/k01157)\
**Post date:** [August 4, 2022, 6:54pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/1 "2022-08-04T18:54:09Z")

</div>

Hi, I use an OpenID Connect enterprise connection to federate users. The returned ID-token contains a custom claim that represents the roles of the given user. I want to dynamically map the content of this id-token claim to an Auth0 role in order to get correct content of the permissions claim in the returned access token from Auth0. Is this possible?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 5, 2022, 12:20am UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/3 "2022-08-05T00:20:28Z")

</div>

Hi there @k01157! We’ll see if anyone chimes in on [this topic](https://community.auth0.com/t/map-roles-to-user-from-external-identity-provider/40757/5?preview_theme_id=30), but perhaps you could use the Management API in an Action to [create/update the role](https://auth0.com/docs/api/management/v2/#!/Roles/get_roles) using the custom claim data?

[https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947](https://community.auth0.com/t/how-can-i-use-the-management-api-in-actions/64947)

---

<div class="post-metadata">

**Author:** ![k01157](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/k01157/32/39147_2.png) [@k01157](https://community.auth0.com/u/k01157)\
**Post date:** [August 5, 2022, 6:45pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/4 "2022-08-05T18:45:37Z")

</div>

Hi @ty.frith and thanks for the reply! I have managed to set roles with the Management API that you suggested. But I am not sure if this solution will scale? I must execute 2 Management API calls for every authentication, one to get user-details that contains my custom claim data and one to assign roles accordingly. The documentation mentions rate-limiting for the Management API and our peak hours in production contains hundreds of logins per second. What do you think about that scenario?

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 5, 2022, 11:47pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/5 "2022-08-05T23:47:45Z")

</div>

No problem, happy to help!

> [@k01157](#):
>
> The documentation mentions rate-limiting for the Management API and our peak hours in production contains hundreds of logins per second. What do you think about that scenario?

I think you are correct in being concerned that this approach will not scale to such a level - This is unfortunately a tricky spot to be in as there aren’t any great options given that each login would require multiple calls to the Management API. This probably wasn’t the best recommendation from the get go!

Not nearly as dynamic but perhaps you could do something like [add the incoming role](https://auth0.com/docs/manage-users/user-accounts/metadata/manage-user-metadata) to a user’s [metadata](https://auth0.com/docs/manage-users/user-accounts/metadata) property and then use the Management SDK elsewhere to make bulk updates?

Again, there unfortunately isn’t a straightforward solution I’m aware of 😕

---

<div class="post-metadata">

**Author:** ![k01157](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/k01157/32/39147_2.png) [@k01157](https://community.auth0.com/u/k01157)\
**Post date:** [August 6, 2022, 5:07pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/6 "2022-08-06T17:07:58Z")

</div>

I’m afraid that will not work? My understanding is that it has to be a synchronous operation in order to get the correct content in the returned access token? (The permission claim is deduced from the roles)

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 21, 2022, 5:08pm UTC](https://community.auth0.com/t/automatically-assign-roles-to-federated-oidc-users/88217/7 "2022-08-21T17:08:07Z")

</div>

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