Triggers->postLogin->exports.onExecutePostLogin | Not reflect custom data | Not working

Hello all,
Need your help or advice:

Trying to pass any custom data via setCustomClaim but without success.
Missing pemissions or any checkbox to set to enable pass custom data on token?

api.accessToken.setCustomClaim('data1','data1');
api.idToken.setCustomClaim('data2', 'data2');

Trying to see on Token any custom data that I’m trying to pass but without success:

FE: @auth0/auth0-spa-js

auth0ClientInstance = new Auth0Client(with relevant info +   
  authorizationParams: {
      audience: 'https://my-auth0.com/api/v2/',
      redirect_uri: window.location.origin + '/auth/auth0/callback',
    });


Token = auth0ClientInstance.getTokenSilently()

Currently on Token only data below:

{
  "iss": "https://https://my-auth0.com/",
  "sub": "auth0|asdasdasdadadad",
  "aud": [
    "https://https://my-auth0.com/api/v2/",
    "https://https://my-auth0.com/userinfo"
  ],
  "iat": 1737303638,
  "exp": 1737390038,
  "scope": "openid profile email",
  "org_id": "org_adsasdasdadad",
  "azp": "ssdasdadasdasdadadad"
}

Hi @vova ,

Please look at this documentation to set custom claims on access_token.

You would want to use onExecuteCredentialsExchange in your action.

Hi @vova

Welcome to the Auth0 Community!

Thank you for posting your question, I’ve checked your action code in my tenant, and it correctly added claims to the ID Token and access token. Could you check if your application is passing the audience in the request? I’m guessing that you could be getting an opaque token, not a valid JWT → Why Access Token Is Not a JWT (Opaque Token). You can also use Auth0 CLI with auth0 test token command to check the access token.

Thanks
Dawid

Thank you for response, we manage to get claims but now org_id dissappeared from token ;(

Q: To get org_id on the acces token need any specific configuration/scope/audience_permissions or any or this is should be a default behaviour?

Thank you for your response!

We managed get custom claims but we faced with additional problem:

We have a regular Login flow with Select Organization.

  1. User click on login then we have default Auth0 popup screen user enter user/pass and moved to selected organizations on default Auth0 select

  2. After select organization moved to callback function getToken and proceed. All working good BUT:
    ISSUE: After initial login we don’t see on an access token the org_id.
    But if user make switch organization by example below and pass in authorizationParams organizationId then access token include the org_id but after initial login auth0Client!.loginWithRedirect() and default select organization flow by autQuesionh0 the access token not include org_id.
    Q: What are we missing? Is it the correct process?

For internal switch account:
auth0Client!.getTokenWithPopup({
authorizationParams: {
organization: orgId,
},
}