# Not receiving Roles in Access Token (Blazor WASM SPA)

**URL:** <https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163>\
**Category:** Get Help\
**Created:** [November 15, 2021, 3:29pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163 "2021-11-15T15:29:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AuthUser](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/authuser/32/25187_2.png) [@AuthUser](https://community.auth0.com/u/AuthUser)\
**Post date:** [November 15, 2021, 3:29pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163/1 "2021-11-15T15:29:38Z")

</div>

Hello,  
I’m trying to apply Role Based Authorization in my Blazor WASM SPA. My main use case would be to use the [Authorize(Role = “SomeRole”)] attribute on my components.

For some reason, the Roles I assign to a user don’t appear in the ID Token (as expected), but they don’t appear in the Access Token either.  
This is my config in program.cs:  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/a/e/aede7adf1b9195a34cfbd7fa968710d612d99a59.png)

I found the above config here:

> **[How to Secure Blazor WASM Applications with Auth0](https://auth0.com/blog/securing-blazor-webassembly-apps/)**
>
> Learn how to secure Blazor WebAssembly applications with Auth0.

I can confirm that the Role has indeed been assigned to the user I’m logged in with.

The Access Token Looks like this:  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/b/f/bfac8f6a11c561d81529c535901c596fc07cdef8.png)

The ID Token looks like this:  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/d/4/d4611479692f8997481cf20ccff4a4c6b4de5b8f.png)

How come the roles do not get passed along with the Access Token?  
Note I also enabled the following in the API settings:  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/2/d/2d63b2446d46a2222459d3b54bb1c85e5b6a382f.png)

As an alternative, it seems like I can use the Permissions from the Access Token instead. Even though I feel like this defeats the purpose of Roles existing out of multiple permissions completely.  
I hope someone can help me out here.  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 15, 2021, 10:53pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163/3 "2021-11-15T22:53:17Z")

</div>

Hi @AuthUser,

Welcome to the Auth0 Community!

You will need to set up an action to add roles to the token in a custom claim. Here is an example:

> **[Login Flow](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)**
>
> Learn about the Actions Login Flow and the post-login Action trigger, which is executed after a user logs in and when a Refresh Token is requested.

---

<div class="post-metadata">

**Author:** ![AuthUser](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/authuser/32/25187_2.png) [@AuthUser](https://community.auth0.com/u/AuthUser)\
**Post date:** [November 16, 2021, 1:00pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163/4 "2021-11-16T13:00:56Z")

</div>

Hi @dan.woda

Thanks for your response.  
I gave the Actions a try, but for some reason; they didn’t work for me.

After a couple of tries, I found out about the “Rules”, which did the trick for me.

I use an altered version of this function:

```auto
function (user, context, callback) {
  const namespace = 'http://demozero.net';
  const assignedRoles = (context.authorization || {}).roles;

  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};

  idTokenClaims[`${namespace}/roles`] = assignedRoles;
  accessTokenClaims[`${namespace}/roles`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;

  callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [November 16, 2021, 9:38pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163/5 "2021-11-16T21:38:19Z")

</div>

Great, thanks for posting for solution.

---

<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:** [December 1, 2021, 9:39pm UTC](https://community.auth0.com/t/not-receiving-roles-in-access-token-blazor-wasm-spa/73163/6 "2021-12-01T21:39:03Z")

</div>

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