Skip to content

Commit

Permalink
feat: add sso provider id to list of groups (PS-236)
Browse files Browse the repository at this point in the history
  • Loading branch information
splaunov committed Feb 25, 2024
1 parent 6a94bd6 commit 2d51fbd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions selfservice/strategy/oidc/strategy_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ func (s *Strategy) updateIdentityFromClaimsAndPersist(w http.ResponseWriter, r *
}

vm.ExtCode("claims", jsonClaims.String())
vm.ExtVar("provider", provider.Config().ID)
jsonIdentity, err := json.Marshal(i)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions selfservice/strategy/oidc/strategy_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ func (s *Strategy) createIdentity(w http.ResponseWriter, r *http.Request, a *reg
}

vm.ExtCode("claims", jsonClaims.String())
vm.ExtVar("provider", provider.Config().ID)
evaluated, err := vm.EvaluateAnonymousSnippet(provider.Config().Mapper, string(jsonnetSnippet))
if err != nil {
return nil, nil, s.handleError(w, r, a, provider.Config().ID, nil, err)
Expand Down
4 changes: 2 additions & 2 deletions selfservice/strategy/oidc/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func TestStrategy(t *testing.T) {
assertIdentity(t, res, body)
expectTokens(t, "valid", body)
assert.Equal(t, "valid", gjson.GetBytes(body, "authentication_methods.0.provider").String(), "%s", body)
assert.Equal(t, "", gjson.GetBytes(body, "identity.metadata_public.groups").String(), "%s", prettyJSON(t, body))
assert.Equal(t, "", gjson.GetBytes(body, "identity.metadata_public.sso_groups.valid").String(), "%s", prettyJSON(t, body))
})

t.Run("case=should pass login", func(t *testing.T) {
Expand All @@ -479,7 +479,7 @@ func TestStrategy(t *testing.T) {
assertIdentity(t, res, body)
expectTokens(t, "valid", body)
assert.Equal(t, "valid", gjson.GetBytes(body, "authentication_methods.0.provider").String(), "%s", body)
assert.Equal(t, `["group1","group2"]`, gjson.GetBytes(body, "identity.metadata_public.groups").String(), "%s", prettyJSON(t, body))
assert.Equal(t, `["group1","group2"]`, gjson.GetBytes(body, "identity.metadata_public.sso_groups.valid").String(), "%s", prettyJSON(t, body))
})
})

Expand Down
9 changes: 7 additions & 2 deletions selfservice/strategy/oidc/stub/oidc.hydra.login.jsonnet
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
local claims = std.extVar('claims');
local provider = std.extVar('provider');
local identity = std.extVar('identity');
local metadata_public = if 'metadata_public' in identity then identity.metadata_public else {};
local mp = if 'metadata_public' in identity then identity.metadata_public else {};

if std.length(claims.sub) == 0 then
error 'claim sub not set'
else
{
identity: {
metadata_public: metadata_public + { [if "groups" in claims.raw_claims then "groups" else null]: claims.raw_claims.groups },
metadata_public: mp {
sso_groups+: {
[if 'groups' in claims.raw_claims then provider]: claims.raw_claims.groups,
},
},
},
}

0 comments on commit 2d51fbd

Please sign in to comment.