Skip to content

Instantly share code, notes, and snippets.

@opsb
Last active October 31, 2016 08:44
Show Gist options
  • Select an option

  • Save opsb/e8dbd5ffe60723902ee3842c605b04c5 to your computer and use it in GitHub Desktop.

Select an option

Save opsb/e8dbd5ffe60723902ee3842c605b04c5 to your computer and use it in GitHub Desktop.
Inject custom claims into auth0 jwt token using a rule
Go the settings page/section: Clients > ClientABC > Advanced Settings > advanced > Application Metadata
And add the metadata, e.g. Key: tenantId, Value: "tenant123"
Include the scope "app_metadata" when calling auth0.login e.g. scope: 'openid offline_access app_metadata'
The tenantId is stored alongside the standard claims e.g.
{
"claims": {
"iss": ...,
"aud": ...,
"app_metadata": {
"tenantId": "tenant123"
}
}
}
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
user.app_metadata.tenantId = context.clientMetadata.tenantId;
callback(null, user, context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment