Add Organization metadata in token


Is it possible to add Organization’s meta_data (key value pair) to the token in sigin in flow? If yes, how?

I am looking for a scenarion where I want to store subscription tier information in the Organization’s metadata and want to make it available to the application in access token.


Hi @bittu.anupam - sure, you can get that out of the event.organization.metadata object in the Action event object: Actions Triggers: post-login - Event Object. Then you can attach it to a custom claim using the API api.accessToken.setCustomClaim method: Actions Triggers: post-login - API Object

Something like this:

exports.onExecutePostLogin = async (event, api) => {
  let namespace = "";
  if (event.organization && event.organization.metadata && event.organization.metadata["subscription"])
    api.idToken.setCustomClaim(`${namespace}subscriptionPlan`, event.organization.metadata["subscription"] );

Thanks for the help! It works!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.