How to make roles a key in JSON rather than namespace - accessing custom claims from NodeJS/Express using Actions

I’ve used an action to add roles my ID token using this script :

exports.onExecutePostLogin = async (event, api) => {
  const namespace = '';
  if (event.authorization) {
    api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
    api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);

But the output of the JSON in the token is now like this :

  '': [ 'user' ],
  nickname: 'test',
  name: '',
  picture: '',
  updated_at: '2022-03-22T14:26:31.519Z',
  email: '',
  email_verified: false,
  sub: 'auth0|6228c2435b5a0b00700561f1'

I EITHER want it to be like

roles: [‘user’]
nickname: ‘test’,

So it is easier to access using req.oidc.user.roles

OR alternatively, how do I access the roles value from here in NodeJS/Express?

Hey there @nc14 !

This is expected behavior and there unfortunately isn’t anyway around the requirement for namespaced custom claims currently. I have heard rumblings that this may be enabled in the future (a common ask), however I’m unable to provide any sort of timeline on that front.