Adding custom claims to tokens

Problem statement: How do I add custom claims to an Access and/or ID Token with Actions?

Solution: Custom claims can be added to an Access/ID Token in a namespaced format by utilizing a Post Login Action. For example:


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

const namespace = 'https://myapp.example.com';

if (event.authorization) {

// Set claims

api.idToken.setCustomClaim(`${namespace}/favorite_color`, favorite_color);

api.idToken.setCustomClaim(`${namespace}/preferred_contact`, preferred_contact);

}

};

Reference Materials :books: :

Related FAQs:

1 Like