Roles missing in access token (JWT)
Hello. I'm trying to request access tokens with projects' roles without success - is this a bug or am I missing something?
Authorization request (line breaks for readability):
Token request body (line breaks for readability):
Retrieved access token
obs.: the role claims are also not present in the id token, but they ARE present in the userinfo response
7 Replies
Here are my setup steps:
1. Setup the main org/project/app:
1. Create a new 'example_org' organization
2. Inside the 'example_org' organization, create a new 'example_project' project
- in the project 'General' settings, enable "Assert Roles on Authentication"
3. Inside the 'example_project' project, create a new 'example_role'
4. Inside the 'example_project' project, create a new 'example_app' (note: I'm using a 'User Agent' app, with PKCE enabled)
- in the app 'Token Settings' settings, set "Auth Token Type" to "JWT"
2. Setup another org with a user:
1. Create a new 'example_org2' organization
2. Inside the 'example_org2' organization, create a new 'example_user' user
3. Grant the user access to the project:
1. Inside the 'example_project' project, grant 'example_role' to the 'example_org2' organization
2. Inside the 'example_org2' organization, grant 'example_role' authorization to the 'example_user' user
userinfo response:
NOTE: selecting "Add user roles to the access token" in the application's "Token Settings" work, but then the roles are retrieved independently of what scopes I pass (i.e.
urn:iam:org:project:roles
and urn:zitadel:iam:org:projects:roles
scopes seem to be ignored)
Also probably relevant: I'm running Zitadel locally with docker-compose v2.71.7hi @bawsky do you have
Add user roles to the access token
enabled within the User Agent app?
Hello @Rajat!
I've actually tried both ways:
- when it's selected, the user roles are ALWAYS added to the access token, regardless of
urn:iam:org:project:roles
and urn:zitadel:iam:org:projects:roles
scopes
- when it is not selected, the user roles are NEVER added to the access token, regardless of urn:iam:org:project:roles
and urn:zitadel:iam:org:projects:roles
scopeshi @bawsky apologies for the trouble :))
as a fallback/workaround, since roles are present in the
/userinfo
response but not in the token, retrieve them via an API call to /oauth/v2/userinfo
after authentication , while I check with my team if its a bug or a feature. If that helps.
ThanksNo trouble at all! We're just starting the work on integrating Zitadel into our already-consolidated product - so this issue doesn't really affect us yet (we are integrating Zitadel for authentication but we still control roles and authorization inside our application - I'm just evaluating the possibility of also migrating that part to Zitadel at some point in future).
Thanks a lot for the response @Rajat 😄
Looking forward to understand this - please keep me updated here (and let me know if I should open a GitHub to track it if it's a bug).
hi @bawsky sure, pls go ahead and open a bug 🙂 tag this thread and someone from the team will take a look and we'll prioritise it