Add custom claims in the tokens
Paid Feature
This is a paid feature.
You can click on the Enable Paid Features button on our dashboard, and follow the steps from there on. Once enabled, this feature is free on the provided development environment.
If you want to add custom properties in the token payloads you can do this by using overrides
1. Override the OAuth2 Access Token
import OAuth2Provider from "supertokens-node/recipe/oauth2provider";
OAuth2Provider.init({
override: {
functions: (originalImplementation) => ({
...originalImplementation,
buildAccessTokenPayload: async (input) => {
const addedInfo: Record<string, any> = {};
if (input.scopes.includes("profile")) {
addedInfo.profile = "custom-value";
}
return {
...(await originalImplementation.buildAccessTokenPayload(input)),
...addedInfo,
};
},
}),
},
});
2. Override the ID Token
import OAuth2Provider from "supertokens-node/recipe/oauth2provider";
OAuth2Provider.init({
override: {
functions: (originalImplementation) => ({
...originalImplementation,
buildIdTokenPayload: async (input) => {
const addedInfo: Record<string, any> = {};
if (input.scopes.includes("profile")) {
addedInfo.profile = "custom-value";
}
return {
...(await originalImplementation.buildIdTokenPayload(input)),
...addedInfo,
};
},
}),
},
});