Last Updated: Aug 13, 2024
Overview
This article details how to set Access Token Claims using Actions.
Applies To
- Access Token
- Claims
- Actions
Solution
t is possible to populate Access Tokens (AT) or ID Tokens with custom claims using a Post Login Action.
Our Post Login Actions have access to two objects that offer different features. These objects are:
The Event object offers access to Properties related to the Authentication Request such as client id, connection name, transaction, etc.
The API object provides a set of Methods that can be used to perform different actions, such as adding custom claims.
-
To add a custom claim to an Access Token, use the following function:
api.accessToken.setCustomClaim(name, value);
-
A complete Post Login Action that adds a custom claim to the AT would look like this:
exports.onExecutePostLogin = async (event, api) => { api.accessToken.setCustomClaim('my-custom-claim', 'my-value'); };
-
Similarly, it is possible to add Custom Claims to an ID Token by referencing it before calling the setCustomClaim function:
api.idToken.setCustomClaim(name, value)