How to add custom claims to the Auth0 Token

How to add these custom claims to the token

https://test/entitlements”:
{
“email”: “jane@example.com”,
“email_verified”: true,
“user_id”: “custom|123”,
“favorite_color”: “blue”,
}

to this token using curl or Node JS

curl --request POST
–url https://test.com/oauth/token
–header ‘content-type: application/json’
–data ‘{“client_id”:“test”,“client_secret”:“test”,“audience”:“https://test.com/api/v2/",“grant_type”:"client_credentials”}’

or Node Js
var request = require(“request”);

var options = { method: ‘POST’,
url: ‘https://test.auth0.com/oauth/token’,
headers: { ‘content-type’: ‘application/json’ },
body: ‘{“client_id”:“test”,“client_secret”:“test”,“audience”:“https://test.auth0.com/api/v2/",“grant_type”:"client_credentials”}’ };

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

Hello, @sriharish_sathyanara,

Custom claims need to be added to the token before they are issued. They can not be added after the token has been issued, as it would invalidate the token’s signature.

You can do this by leveraging a Rule or a Hook, depending on the type of grant that you are executing.

1 Like