I have added below customclaim to my app but it is not applied. I want that when a user login to app idToken or access token have customclaim like below
app_name:"website name"
Below is the code for adding custom claim to IdToken but it not getting added and giving error.
exports.onExecutePostLogin = async (event, api) => {
const namespace = "https://portal.app.com"
const { website } = event.app_metadata;
console.log("app name:",website)
if (event.authorization) {
// Set claims
api.idToken.setCustomClaim(`${namespace}/app/name`, website);
}
};
Event object passed to test.
{
"created_at": "2023-08-07T09:48:10.750Z",
"email": "learner@gmail.com",
"email_verified": false,
"identities": [
{
"connection": "Username-Password-Authentication",
"user_id": "64d0bddaadf0a94c33d33795",
"provider": "auth0",
"isSocial": false
}
],
"name": "learner@gmail.com",
"nickname": "learner",
"picture": "https://s.gravatar.com/avatar/b3118e351aa0b1db98fc5d2c61ba8a3f?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Fle.png",
"updated_at": "2023-08-07T09:48:10.750Z",
"user_id": "auth0|64d0bddaadf0a94c33d33795",
"username": "learner",
"app_metadata": {
"website": "anasuria"
},
"blocked_for": [],
"guardian_authenticators": []
}
Response received
Test Results
Commands:
[]
Error:
{}
Logs:
app name: anasuria
Stats:
{
"total_request_duration_ms": 295,
"total_runtime_execution_duration_ms": 291,
"runtime_processing_duration_ms": 5,
"action_duration_ms": 208,
"runtime_external_call_duration_ms": 78,
"boot_duration_ms": 83,
"network_duration_ms": 4
}