I am trying to add information from app_metadata
to a user’s profile after login using a rule. However, app_metadata
doesn’t appear to be available from within the rule. Is it possible I am not sending along enough information using the “Try This Rule” button?
The code for the rule is below.
function (user, context, callback) {
const namespace = 'https://somedomain.com/';
context.idToken[namespace + 'app_metadata'] = user.app_metadata || "nothing";
callback(null, user, context);
}
The context information from the “Try This Rule” modal is below. It’s all the default text except I updated clientId
to the appropriate value and I added app_metadata
to the profile (I read somewhere to do that).
{
"clientID": "12345",
"clientName": "MyWebApp",
"connection": "MyDbConn",
"connectionStrategy": "auth0",
"protocol": "oidc-basic-profile",
"request": {
"query": { "scope": "openid profile app_metadata" }
},
"samlConfiguration": {},
"stats": { "loginsCount": 5 },
"accessToken": {},
"idToken": {}
}
When I execute the rule, the portion of the token that I expect to contain app_metadata
is blank because user.app_metadata
is empty even though the user I am testing with contains app_metadata
values.
"idToken": {
"https://somedomain.com/app_metadata": "nothing"
}
I didn’t modify clientName
, connection
, connectionStrategy
, etc., within the context and maybe that is causing the problem or is it something else?