# How to use Rules to add user roles based on AD group membership

**URL:** <https://community.auth0.com/t/how-to-use-rules-to-add-user-roles-based-on-ad-group-membership/7408>\
**Category:** Get Help\
**Tags:** rules, groups, roles\
**Created:** [July 7, 2017, 3:05am UTC](https://community.auth0.com/t/how-to-use-rules-to-add-user-roles-based-on-ad-group-membership/7408 "2017-07-07T03:05:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccruz1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@ccruz1](https://community.auth0.com/u/ccruz1)\
**Post date:** [July 7, 2017, 3:05am UTC](https://community.auth0.com/t/how-to-use-rules-to-add-user-roles-based-on-ad-group-membership/7408/1 "2017-07-07T03:05:14Z")

</div>

We have a few hundred users that we are moving to Auth0 to access our intranet site. We would like to add the proper roles for user when they login based on their existing AD group memberships.

I’ve got as far as getting the groups to show up in the user object but I’m unclear of how to populate the roles in the correct scope under app\_metadata. Based on the obligatory searching, I can add roles manually to app\_metadata, but it populates under the wrong section using the default “Set roles to a user” template :

Desired output:  
`{ "authorization": { "roles": "Role1" ], "permissions": ] } }`

Current output:  
`{ "authorization": { "roles": ], "permissions": ] } "roles": "Role1" ] }`

I’m sure it’s an extremely simple matter of syntax.

I also have not been able to find a working example of how to iterate through the “groups” profile data.

Any help would be much appreciated!

---

<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:** [March 2, 2018, 5:55am UTC](https://community.auth0.com/t/how-to-use-rules-to-add-user-roles-based-on-ad-group-membership/7408/2 "2018-03-02T05:55:12Z")

</div>


