Custom rule to add user.app_metadata to accessToken does not trigger


I set up a custom rule to add user.app_metadata to the accessToken, which I retrieve when logging in.
I did not set any other configuration as I assume that rules work on every request when they are enabled.

I use the auth0-js client library and can successful login and retrieve a accessToken.

This is my rule:

function (user, context, callback) {
 const namespace = "https://my_namespace/"; // my_namespace is a placeholder...

  context.accessToken[namespace + "app_metadata"] = user.app_metadata;

  callback(null, user, context);

This is my client setup:

const auth0Client = new auth0.WebAuth({
    domain: config.AUTH0_DOMAIN,
    audience: "https://${config.AUTH0_DOMAIN}/userinfo",
    clientID: config.AUTH0_CLIENT_ID,
    redirectUri: config.AUTH0_REDIRECT_URL,
    responseType: "id_token",
    scope: "openid profile email",

Hi @glennydc,

Are you sure you are getting an access token and not an ID token? I believe you need to specify token in your response type if you want an access token.

Otherwise, your rule looks fine to me. This is my template rule for that use case: