# Add user attributes to idToken

**URL:** <https://community.auth0.com/t/add-user-attributes-to-idtoken/62903>\
**Category:** Get Help\
**Tags:** actions, login\
**Created:** [May 17, 2021, 7:47am UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903 "2021-05-17T07:47:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver.back](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oliver.back/32/12898_2.png) [@oliver.back](https://community.auth0.com/u/oliver.back)\
**Post date:** [May 17, 2021, 7:47am UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/1 "2021-05-17T07:47:19Z")

</div>

Im trying to replicate what an existing rule does, but in an action.  
I have a rule that adds a users Identity Provider Attribute called roles to the idToken.

I can see the example docs allows you to add roles from event.authorization.roles, but I am trying to add from the user attributes. The following adds the claim, but the value is null.

![image](https://global.discourse-cdn.com/auth0/original/3X/e/5/e55e6c3e77c53fd66dde0e0b9fd7e4b92312648a.png)

I can see the user profile doesnt have roles as a property hence the error. Is there a correct way to do this or are the attributes elsewhere.  
Thanks

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 17, 2021, 1:33pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/3 "2021-05-17T13:33:08Z")

</div>

Hi @oliver.back,

You can set a custom claim for the user’s roles by using `event.authorization.roles`:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'https://test.com/';
  const roles = (event.authorization || {}).roles || [];
  api.idToken.setCustomClaim(`${namespace}roles`, roles);
};

```

[https://auth0.com/docs/actions-event-object](https://auth0.com/docs/actions-event-object)

---

<div class="post-metadata">

**Author:** ![oliver.back](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oliver.back/32/12898_2.png) [@oliver.back](https://community.auth0.com/u/oliver.back)\
**Post date:** [May 17, 2021, 2:37pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/4 "2021-05-17T14:37:00Z")

</div>

Hi

Thanks, I think event.authorization.roles are roles specific to auth0 applications?  
Im using a Azure AD enterprise connection which in turn adds the Azure AD application assigned roles to the users identity provider attributes.  
It is this specific attribute called “roles” im looking to add as a claim. Hope that makes sense

thanks!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 17, 2021, 7:33pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/5 "2021-05-17T19:33:41Z")

</div>

I see, that makes sense! I am not too familiar with Azure AD, and so I will have to research this. I don’t believe there are any attributes outside of what is described in the event object here: [https://auth0.com/docs/actions-event-object?\_ga=2.49400101.2047594292.1621254077-1595415333.1607347674&\_gac=1.19324234.1620663261.Cj0KCQjws-OEBhCkARIsAPhOkIbhK13acrxZIWhKyPE4GlpGf7ZKmKpxtmuQbD\_VcaLmyScFgvNZcmAaAntFEALw\_wcB](https://auth0.com/docs/actions-event-object?_ga=2.49400101.2047594292.1621254077-1595415333.1607347674&_gac=1.19324234.1620663261.Cj0KCQjws-OEBhCkARIsAPhOkIbhK13acrxZIWhKyPE4GlpGf7ZKmKpxtmuQbD_VcaLmyScFgvNZcmAaAntFEALw_wcB)

I’m curious if the roles would be available in the `waad` item in the `event.user.identities array` in `profileData`

---

<div class="post-metadata">

**Author:** ![oliver.back](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oliver.back/32/12898_2.png) [@oliver.back](https://community.auth0.com/u/oliver.back)\
**Post date:** [May 18, 2021, 7:08am UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/6 "2021-05-18T07:08:40Z")

</div>

I just checked…  
It doesnt seem the roles are available in the waad item in event.user.identities.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 18, 2021, 12:21pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/7 "2021-05-18T12:21:16Z")

</div>

Thanks for testing that. I’ve reached out to the engineering team about this and I will let you know when I hear back.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 18, 2021, 2:30pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/8 "2021-05-18T14:30:33Z")

</div>

Hi @oliver.back, the engineering team is working to find a solution for this use case in actions. I will keep you updated!

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 18, 2021, 3:58pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/9 "2021-05-18T15:58:44Z")

</div>

I have received another update from the Engineering team. An issue has been created for this to allow additional root profile fields from the identity provider (eg Azure AD) to be available in Actions. Unfortunately, I don’t have an estimated date on when this will be available, but I will update when available.

---

<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:** [June 25, 2021, 12:57pm UTC](https://community.auth0.com/t/add-user-attributes-to-idtoken/62903/10 "2021-06-25T12:57:18Z")

</div>

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