# API Permissions not in User.Claims

**URL:** <https://community.auth0.com/t/api-permissions-not-in-user-claims/123425>\
**Category:** Get Help\
**Tags:** login-experience, new-universal-login-experience\
**Created:** [December 20, 2023, 11:23am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425 "2023-12-20T11:23:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnyb](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jonnyb](https://community.auth0.com/u/jonnyb)\
**Post date:** [December 20, 2023, 11:23am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/1 "2023-12-20T11:23:33Z")

</div>

I’m using Blazor Server.

I’m using Auth0 for application authentication and I’m using API Permissions for more fine-grained authz. Most of it is working, but I’m at a loss on how to get the API Permissions into the User.Claims.

1. I’m able to get the right permissions from the access token using HttpContext.GetTokenAsync(“access\_token”)

But, I was expecting the API permissions to be included in User.Claims

Should the API permissions be there by default or do I have to do something special?

I have flipped the bit in settings for RBAC and include in Access Token, and they are there.

But they just don’t show up in User.Claims. I could look at creating a customerAuthenticationStateProvider, but I think I’m missing something simple.

Thanks!

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [December 20, 2023, 3:53pm UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/2 "2023-12-20T15:53:51Z")

</div>

Hi @jonnyb , welcome to Auth0!

> [@jonnyb](#):
>
> Should the API permissions be there by default or do I have to do something special?

The permissions should be there. If the API is configured:

- with RBAC and
- enabled the **Add Permissions in the Access Token** toggle and
- your test user is correctly assigned to permissions,

then the “permissions” claim should be available in the access token.  
Do you see the “permissions” claim there?

---

<div class="post-metadata">

**Author:** ![jonnyb](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jonnyb](https://community.auth0.com/u/jonnyb)\
**Post date:** [December 21, 2023, 1:55am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/3 "2023-12-21T01:55:11Z")

</div>

Here’s my full setup:

1. Default app

2. API app with one permission “download:files”

3. User is assigned to both the Admin role which has the download:files permission as well as the direct assignment to the permission.  
 ![image](https://global.discourse-cdn.com/auth0/original/3X/4/1/414f5b1d25f4c99f73a3f9887713a959c35ee987.png)

4. RBAC toggled  

5. Login flow:

![image](https://global.discourse-cdn.com/auth0/original/3X/2/2/228602bb4c92925ac905d69e74354cad09cffc43.png)

```auto
exports.onExecutePostLogin = async (event, api) => {
  const roleClaim = 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role';
  
  if (event.authorization) {
    api.idToken.setCustomClaim(roleClaim, event.authorization.roles);
  }
};

```

1. Program.cs

```auto
builder.Services.AddAuth0WebAppAuthentication(options =>
{
    options.Domain = builder.Configuration["Auth0:Domain"]!;
    options.ClientId = builder.Configuration["Auth0:ClientId"]!;
    options.ClientSecret = builder.Configuration["Auth0:ClientSecret"]!;
    options.ResponseType = "code";
})
.WithAccessToken(options =>
{
    options.Audience = builder.Configuration["Auth0:Audience"];
    options.UseRefreshTokens = true;
});

```

To re-iterate, everything is working EXCEPT my User.Claims doesn’t have permissions.

Thoughts?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [December 22, 2023, 12:03pm UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/4 "2023-12-22T12:03:22Z")

</div>

Hi @jonnyb ,

Thanks for this summary!

> [@jonnyb](#):
>
> To re-iterate, everything is working EXCEPT my User.Claims doesn’t have permissions.

Alright, you mean ID token.

Could you try updating a bit your Actions script:

```auto
exports.onExecutePostLogin = async (event, api) => {
  const roleClaim = 'http://schemas.microsoft.com/ws/2008/06/identity/claims/role';
  
  if (event.authorization) {
    api.idToken.setCustomClaim(`${roleClaim}/roles`, event.authorization.roles);
  }
};

```

And see if the ID token after decoding with [jwt.io](http://jwt.io) contains the claim added via Actions?

---

<div class="post-metadata">

**Author:** ![jonnyb](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@jonnyb](https://community.auth0.com/u/jonnyb)\
**Post date:** [December 24, 2023, 11:12am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/5 "2023-12-24T11:12:07Z")

</div>

Thanks for having a look! I updated the Actions script. The Roles are there, but the API Permissions are not.

Any other ideas?

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [January 2, 2024, 11:00am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/6 "2024-01-02T11:00:21Z")

</div>

Hi @jonnyb , welcome in 2024!

> [@jonnyb](#):
>
> The Roles are there, but the API Permissions are not.

After additional investigation I can tell that the role-based API permissions are intended to be present in the Access Token and with the Actions Script it’s possible to only enrich the ID token with Roles cliam.

> [@jonnyb](#):
>
> Any other ideas?

One way that comes to my mind, if you need this data within the ID token, is to update the user’s app\_metadata or user\_metadata object with the API permissions and add a custom claim to the ID token containing this metadata (in a similar way you added the Roles claim).

This Management API endpoint lists user’s permissions (both assigned directly and ones that come from Role assignment) - [Auth0 Management API v2](https://auth0.com/docs/api/management/v2/users/get-permissions)  
They are listed per the resource\_server\_identifier (your API identifier).

In the Actions script you can also refer to the `event.resource_server` object and try to use this identifier to extract only the relevant for the login context API permissions.

One of our community folks has tried to implement it using rules (soon deprecated) so maybe you can use it as a reference when building Actions script- [Accessing the permissions array in the access token - #10 by ryantomaselli](https://community.auth0.com/t/accessing-the-permissions-array-in-the-access-token/27559/10)

---

<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:** [January 16, 2024, 11:00am UTC](https://community.auth0.com/t/api-permissions-not-in-user-claims/123425/7 "2024-01-16T11:00:39Z")

</div>

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