Auth0 not returning user roles - Angular SPA

Hi community,

I’m facing an issue and I would like to know how to get the role data from user. The authentication is working well, the problem is that when I get the data from the user, I don’t have any property with the roles.

What I already did:

1 - Activate both options.

2 - Library used: @auth0/auth0-angular

3 - I expect to see both properties below. But the properties are not there like the printscreen.

The observable that returns the user data is user$

Expected result:

image

Current result:

image

Is there anything else to do? Am I missing any configuration?

Cheers,
Guilherme Marques.

Hello @it-phoenix welcome back!

It looks like the data you’ve shared is tied to an ID token whereas the RBAC/Permissions settings apply to Access tokens. You’ll want to take a look at the following FAQ which outlines how to add roles/permissions to an ID token:

Let us know if you have any questions!

2 Likes

Hi tyf,
Thanks for the help.
We could fix the issue create a new rule.

Auth Pipeline - Rules - We added the following rule.

function (user, context, callback) {
  const namespace = 'http://schemas.microsoft.com/ws/2008/06/identity/claims';
  const assignedRoles = (context.authorization || {}).roles;
	const ManagementClient = require('auth0@2.17.0').ManagementClient;
  const management = new ManagementClient({token: auth0.accessToken,domain: auth0.domain});
  
 //  const params = { id: user.user_id, page: 0, per_page: 50, include_totals: true };
  
  let idTokenClaims = context.idToken || {};
  let accessTokenClaims = context.accessToken || {};
	
  

  idTokenClaims[`${namespace}/role`] = assignedRoles;
  accessTokenClaims[`${namespace}/role`] = assignedRoles;

  context.idToken = idTokenClaims;
  context.accessToken = accessTokenClaims;
  callback(null, user, context);
}

Cheers,
Guilherme Marques.

2 Likes

No problem, happy to help! Good to know you were able to get this sorted with the new rule, and thanks for following up with the community :smile:

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