I created both app and API profiles in Auth0 and have successfully been able to pass needed information along with a bearer token sent to the API by using this code in a custom action:
/**
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login.
*/
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://api_1';
if (event.authorization) {
api.idToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
api.accessToken.setCustomClaim(`${namespace}/roles`, event.authorization.roles);
api.idToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
api.accessToken.setCustomClaim(`${namespace}/ip`, event.request.ip);
}
}
However, I need to do something similar for another API (let’s call its namespace https://api_2). Do I just copy this custom action and make another one that I add to the login flow below the existing one?