Last active
December 15, 2021 00:12
-
-
Save phiniezyc/d7241f6710da388b05f4f6e4d5090fc8 to your computer and use it in GitHub Desktop.
Auth0 Rule to Add User Roles to Tokens (Access and Id Tokens). Set in Auth0 Rules:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function setRolesToUser(user, context, callback) { | |
| const namespace = 'http://my-website-name.com'; | |
| const assignedRoles = (context.authorization || {}).roles; | |
| let idTokenClaims = context.idToken || {}; | |
| let accessTokenClaims = context.accessToken || {}; | |
| idTokenClaims[`${namespace}/roles`] = assignedRoles; | |
| accessTokenClaims[`${namespace}/roles`] = assignedRoles; | |
| context.idToken = idTokenClaims; | |
| context.accessToken = accessTokenClaims; | |
| callback(null, user, context); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment