# Cant add app\_metadata to accessToken

**URL:** <https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717>\
**Category:** Get Help\
**Tags:** client-grants, management-api\
**Created:** [January 8, 2023, 4:03pm UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717 "2023-01-08T16:03:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivelin.kotsev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivelin.kotsev/32/42401_2.png) [@ivelin.kotsev](https://community.auth0.com/u/ivelin.kotsev)\
**Post date:** [January 8, 2023, 4:03pm UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/1 "2023-01-08T16:03:25Z")

</div>

Hi guys I’ve tried to add app\_metadata to accessToken but without any luck.  
My app is Blazor(Server&Client)  
Things I have tried add successfully app\_metadata to IDToken but now in AccessToken  
Actions → Flow → Login

```auto
exports.onExecutePostLogin = async (event, api) => {
  const namespace = 'IKActionFlows';
  api.accessToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
  api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.user.app_metadata);
};

```

Auth Pipeline → Rules

```auto
function addAppMetadataToAccessToken(user, context, callback) {
  var namespace = 'IKAuthPipeline';
  context.accessToken[namespace + 'app_metadata'] = user.app_metadata;
  return callback(null, user, context);
}

```

This is my Program.css of Client(BlazorWASM)

```auto
builder.Services.AddOidcAuthentication(options =>
{
    builder.Configuration.Bind("Auth0", options.ProviderOptions);
    options.ProviderOptions.ResponseType = "code";

    options.ProviderOptions.AdditionalProviderParameters.Add("audience", builder.Configuration["Auth0:Audience"]);
});

```

This is my Program.cs for Blazor(Server)

```auto

 appBuilder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
        .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, c =>
        {
            c.Authority = $"https://{appBuilder.Configuration["Auth0:Domain"]}";
            c.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
            {
                ValidAudience = appBuilder.Configuration["Auth0:Audience"],
                ValidIssuer = $"https://{appBuilder.Configuration["Auth0:Domain"]}"
            };
        });

```

Can anyone give me any clue what I do wrong ? Thanks

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 9, 2023, 9:14am UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/2 "2023-01-09T09:14:34Z")

</div>

Hey there!

Thank you for raising this! @andrea.chiarelli as a Blazor expert would you be able to help us on that front? Kudos!

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 9, 2023, 10:43am UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/3 "2023-01-09T10:43:04Z")

</div>

Hey @ivelin.kotsev,  
Welcome to the Auth0 Community!

As far as I can see, most likely your problem does not depend on Blazor configuration.  
At first glance, I have a couple of concerns:

1. Why are you using both Actions and Rules to set custom claims to the token(s)?  
If you use both, Rules are executed before Actions, but using both in this case looks redundant.  
The recommended approach is to use just Actions.

2. As far as I know, suggested namespaces should follow the [URI syntax](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#namespaced-guidelines). Also, [namespaced claims are mandatory for access tokens](https://auth0.com/docs/secure/tokens/json-web-tokens/create-custom-claims#general-restrictions).

Please, try to fix your Action following these guidelines, although I’m not 100% sure that they will fix the issue. Let me know.

---

<div class="post-metadata">

**Author:** ![ivelin.kotsev](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ivelin.kotsev/32/42401_2.png) [@ivelin.kotsev](https://community.auth0.com/u/ivelin.kotsev)\
**Post date:** [January 9, 2023, 11:06am UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/4 "2023-01-09T11:06:20Z")

</div>

Thank you for the cooperation!  
I’ve tried both Actions and Rules, because I’ve couldn’t make it work and got desperate 😄

Fixing the Namespace fixed my problem!

Thank you @andrea.chiarelli and @konrad.sopala !

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [January 9, 2023, 11:13am UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/5 "2023-01-09T11:13:21Z")

</div>

Happy to hear this! 🎉 Have a great week, @ivelin.kotsev!

---

<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 23, 2023, 11:13am UTC](https://community.auth0.com/t/cant-add-app-metadata-to-accesstoken/97717/6 "2023-01-23T11:13:25Z")

</div>

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