Skip to main content
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.

Add custom claims in the tokens

If you want to add custom properties in the token payloads you can do this by using overrides

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,
};
},
}),
},
});

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,
};
},
}),
},
});

Looking for older versions of the documentation?
Which UI do you use?
Custom UI
Pre built UI