Hi @maxime.fleury,
Welcome to the Auth0 Community!
Custom claims can be added to an Access/ID Token in a namespace
format by utilizing a Post Login Action. For example:
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://myapp.example.com';
const { favorite_color, preferred_contact } = event.user.user_metadata;
if (event.authorization) {
// Set claims in ID token
api.idToken.setCustomClaim(`${namespace}/favorite_color`, favorite_color);
api.idToken.setCustomClaim(`${namespace}/preferred_contact`, preferred_contact);
// Set claims in access token
api.accessToken.setCustomClaim(`${namespace}/favorite_color`, favorite_color);
api.accessToken.setCustomClaim(`${namespace}/preferred_contact`, preferred_contact);
}
};
Also please check these articles:
- Adding Custom Claims to ID Tokens with Auth0 Actions
- Login Flow
- Create Custom Claims
- Sample Use Cases: Scopes and Claims
Related FAQs:
Thanks,
Timotei