setCustomClaim doesn't seem to work

exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("person_id", event.client.metadata.uuid )

I’m trying to add a key to the token used for API calls. I’m using the code above within this simple flow:

The token passed to my server does not have person_id, though. Feels like I’m close, here…

Hi @dudo,

Can you try using a namespaced claim to see if that is the problem?

You may also need to toggle on non-namespaced custom claims (we are currently working through a migration).

Tried this:

exports.onExecuteCredentialsExchange = async (event, api) => {
  const namespace = ""
  api.accessToken.setCustomClaim(`${namespace}/person_id`, event.client.metadata.uuid )


Just to be clear, onExecuteCredentialsExchange is where I get a token via getAccessTokenSilently, yes?

Also, I don’t see that migration in my dev tenant

No, I didn’t catch that. This is likely the issue. You are not making a client credentials request when you are using getAccessTokenSilently.

You should use a Login Flow Action instead.

I also tried that, with no success… w/ and w/o namespacing.

exports.onExecutePostLogin = async (event, api) => {
  const namespace = ""
  api.idToken.setCustomClaim(`${namespace}/person_id`, event.user.app_metadata.uuid);

I don’t love how the api to get a handle on the token is different… or am I calling that incorrectly?

api.accessToken not api.idToken. We’re good! Thank you, @dan.woda

1 Like

Glad we figured it out! Cheers!

1 Like

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