When I implement Auth0 Authentication and “Set Roles to User” Rule
function (user, context, callback) {
const namespace = 'https://dev-o0hx8kbg.us.auth0.com';
const assignedRoles = (context.authorization || {}).roles;
const assignedPermis = (user.app_metadata || {}).permissions;
let idTokenClaims = context.idToken || {};
let accessTokenClaims = context.accessToken || {};
idTokenClaims[`${namespace}/roles`] = assignedRoles;
accessTokenClaims[`${namespace}/roles`] = assignedRoles;
idTokenClaims[`${namespace}/permissions`] = assignedPermis;
accessTokenClaims[`${namespace}/permissions`] = assignedPermis;
context.idToken = idTokenClaims;
context.accessToken = accessTokenClaims;
callback(null, user, context);
}
When I am trying to jwt.decode, payload returns
Key Error at "https://dev-o0hx8kbg.us.auth0.com/roles"
Here is below my function in Django for retrieving payload
def get_user_details(self, response):
# Obtain JWT and the keys to validate the signature
id_token = response.get('id_token')
audience = self.setting('SOCIAL_AUTH_AUTH0_KEY') # CLIENT_ID
jwks = request.urlopen(
'https://' + self.setting('SOCIAL_AUTH_AUTH0_DOMAIN') + '/.well-known/jwks.json')
issuer = 'https://' + self.setting('SOCIAL_AUTH_AUTH0_DOMAIN') + '/'
payload = jwt.decode(id_token, jwks.read(), algorithms=[
'RS256'], audience=audience, issuer=issuer)
return {
'username': payload['nickname'],
'first_name': payload['name'],
'picture': payload['picture'],
'user_id': payload['sub'],
'role': payload['https://dev-o0hx8kbg.us.auth0.com/roles']
}