- Created Native application from Dashboard under Application
- Added key value pair under application metadata(Name:OrgA)
- How to add rule to fetch metadata under rule? So that I can view the application metadata while parsing the access token using jwt.
Note: Already defined rule to fetch users roles and permission. How do I differentiate the rule belongs to user and application oriented? If I am using multiple rules means, how do I specify which rule belongs to which one?
Hi there @selvi !
You can add application and/or user metadata to your user’s id/access token by adding a custom claim. You can accomplish this with either a rule:
function (user, context, callback) {
// TODO: implement your rule
const namespace = 'https://myapp.example.com';
context.idToken[namespace + '/user_metadata'] = user.user_metadata;
context.idToken[namespace + '/app_metadata'] = context.clientMetadata;
return callback(null, user, context);
}
Or action (post login):
exports.onExecutePostLogin = async (event, api) => {
const namespace = 'https://my-app.example.com';
if (event.authorization) {
api.idToken.setCustomClaim(`${namespace}/user_metadata`, event.user.user_metadata);
api.idToken.setCustomClaim(`${namespace}/app_metadata`, event.client.metadata);
}
};
I’m not 100% clear on what you mean here, but you could create a separate rule to add metadata - How you namespace the claim is also entirely up to you as well.
Hope this helps!
2 Likes
Thanks it’s working
context.clientMetadata = context.clientMetadata || {};
console.log(context.clientMetadata);
context.idToken[namespace + ‘/app_metadata’] = context.clientMetadata;
context.accessToken[namespace + ‘/app_metadata’] = context.clientMetadata;