Custom client side custom JWT inputs

Hey !

Im trying to add a custom value to my JWT, I have the custom claims set up with the following code in auth0.

exports.onExecutePostLogin = async (event, api) => {

  const input = 'hello'

  if (event.authorization) {
    // Set claims 
    api.idToken.setCustomClaim(`input`, input);
  }
};

Which adds the variable input currently set to ‘hello’. I have also set up the action flow which works fine.

But what I want is to set a custom variable from the client side and set the variable input as that.

See how im making the JWT req below

    // getting user raw JWT token
    const accessToken = await getAccessTokenSilently({

      createJWT: {
        claims: {
          input: 'mockInputInput',
        },
        expiresIn: 3600,
      },
      detailedResponse: true, 
    
    })


    const clientJWT = accessToken.id_token
    console.log(clientJWT) // later add to deploy function for warp contract


    // Decode the JWT to see the claims
  const decodedToken = jwtDecode(clientJWT);
  console.log(decodedToken);

But I am still not getting the custom JWT claim input on the auth0 side

Please advise ! Thanks :slight_smile:

1 Like

Hey !

Im trying to add custom variables to a JWT using the react auth0 SDK, but I want the front end req to specify the values.

I am making the req from the front end like:

const accessToken = await getAccessTokenSilently({
      detailedResponse: true,

      txn_data: '', // custom
      toContractId: '', // custom
      txn_data: '' // custom
      
    })

But the event.request.body has no data as well as the event.request.query does not contain these variables in the actions event.

Help, PLZ

Hi @JohnWick,

Thanks for reaching out to the Auth0 Community!

I see that you have made a post asking a similar question. I have merged them together for consistency.

Thanks,
Rueben

Hi @JohnWick,

Yes, this is to be expected because the Access Token is generated from the authorization server (from Auth0). Moreover, Access Tokens are immutable, meaning they cannot be changed after it has been created.

The recommended way of appending custom claims to the access token is to use an Auth0 Post Login Action, as you have discovered.

I recommend checking out our Adding custom claims to tokens FAQ to learn more about appending custom claims to tokens.

Please let me know if you have any additional questions.

Thanks,
Rueben

Hi Rueben,

I am having trouble getting this to work. I’m trying to set the value of a custom claim from my client (a single page application). Can you direct me on how to do this?

In other words, the custom claim needs to be variable and set programmatically by my application on a per-user basis.

Thanks,

Tate

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