feat(group): add user groups to token claims (#11009)

# Which Problems Are Solved

If the groups of a user is requested through a scope, details related to
the user's groups are added in the token claims.

# How the Problems Are Solved
By querying the user groups that the user is a part of, and setting them
in the token claims.

This PR introduces two scopes to request user groups: `groups` and
`urn:zitadel:iam:user:groups`
* `groups` returns an array of group names in the token claims with the
same name
* `urn:zitadel:iam:user:groups` returns an array of JSON objects with
information about the user groups in the token claims with the same name

# Additional Changes

N/A

# Additional Context

- Closes #9702 
- Follow-up for PRs:
  * #10455 
  * #10853 
  * #10758 
  * #10940

---------

Co-authored-by: Livio Spring <[email protected]>
This commit is contained in:
Gayathri Vijayan
2025-11-11 09:06:45 +01:00
committed by GitHub
co-authored by Livio Spring
parent e4a959c321
commit a9846498a9
8 changed files with 140 additions and 5 deletions
+46
View File
@@ -179,6 +179,16 @@ func Test_userInfoToOIDC(t *testing.T) {
Name: "orgName",
PrimaryDomain: "orgDomain",
}
userGroups := []query.UserInfoUserGroup{
{
Name: "group1",
ID: "group1-id",
},
{
Name: "group2",
ID: "group2-id",
},
}
humanUserInfo := &query.OIDCUserInfo{
User: &query.User{
ID: "human1",
@@ -226,6 +236,7 @@ func Test_userInfoToOIDC(t *testing.T) {
UserResourceOwner: "org1",
},
},
UserGroups: userGroups,
}
machineUserInfo := &query.OIDCUserInfo{
User: &query.User{
@@ -503,6 +514,41 @@ func Test_userInfoToOIDC(t *testing.T) {
},
},
},
{
name: "human, scope custom user groups, found",
args: args{
user: humanUserInfo,
scope: []string{ScopeCustomUserGroups},
},
want: &oidc.UserInfo{
Subject: "human1",
Claims: map[string]any{
ClaimCustomUserGroups: []query.UserInfoUserGroup{
{
Name: "group1",
ID: "group1-id",
},
{
Name: "group2",
ID: "group2-id",
},
},
},
},
},
{
name: "human, scope user groups (group names), found",
args: args{
user: humanUserInfo,
scope: []string{ScopeUserGroups},
},
want: &oidc.UserInfo{
Subject: "human1",
Claims: map[string]any{
ClaimUserGroups: []string{"group1", "group2"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {