# Conditionally add scope based on Auth0 role

**URL:** <https://community.auth0.com/t/conditionally-add-scope-based-on-auth0-role/72761>\
**Category:** Get Help\
**Tags:** role, scope\
**Created:** [November 8, 2021, 1:18pm UTC](https://community.auth0.com/t/conditionally-add-scope-based-on-auth0-role/72761 "2021-11-08T13:18:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emiel](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/emiel/32/33674_2.png) [@emiel](https://community.auth0.com/u/emiel)\
**Post date:** [November 8, 2021, 1:18pm UTC](https://community.auth0.com/t/conditionally-add-scope-based-on-auth0-role/72761/1 "2021-11-08T13:18:14Z")

</div>

Hi there!

Could you help me with the following. Currently our application (.NET Core API) is protected by using `[Authorize("myscope")]`.

A small number of the users defined in our Auth0 tenant have a custom role, _Manager_.

Would it be possible to conditionally add this scope **myscope** to the user’s token only if the user has this role? Would this even be a secure solution or do we need to add the role to the token and check that in the application?

Best regards,

Emiel

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [November 8, 2021, 6:29pm UTC](https://community.auth0.com/t/conditionally-add-scope-based-on-auth0-role/72761/3 "2021-11-08T18:29:38Z")

</div>

Hi @emiel,

Thanks for reaching out to the Auth0 Community!

Yes, it is possible to conditionally add any scope you want to the user’s access token.

To do so, you’ll need to use Auth0 Rules and use the `context.authorization.roles` object to determine if your user matches the _Manager_ role and then modify the `context.accessToken.scope` object to add your custom scopes.

Doing so will allow you to add scopes to the user’s access token conditionally.

You may find our [Context Object Properties in Rules](https://auth0.com/docs/rules/context-object) documentation helpful.

Please let me know if there’s anything else I can do to help.

Thank you.

---

<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:** [November 23, 2021, 6:30pm UTC](https://community.auth0.com/t/conditionally-add-scope-based-on-auth0-role/72761/4 "2021-11-23T18:30:15Z")

</div>

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