Cannot add custom claim to access token via Actions

Hey all,

Trying to add some custom metadata to my access tokens using Actions and it doesn’t seem to be working. Running the action seems ok, I am able to add custom claims to the ID token too. Here is my Action:

exports.onExecutePostLogin = async (event, api) => {
  api.accessToken.setCustomClaim("yahadsf", "working")
  api.idToken.setCustomClaim("idyah", "yah")
  // if (event.authorization) {
  //   api.accessToken.setCustomClaim("myapp_id", event.user.user_metadata.myapp_id);
  // }

Appreciate the help, thanks!

Hi @bmorrisondev

Welcome to the Auth0 Community, it’s great to have you here.

You may need to add a namespace, simplest implementation might look like this:

exports.onExecutePostLogin = async (event, api) => {
  api.accessToken.setCustomClaim("https://mynamespace/fave-colour", "Blue");

You can see more details here

Warm regards.