Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for groups when roles are missing #55

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions genericOidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type GenericOIDCClaims struct {
Name string `json:"name"`
PreferredUsername string `json:"preferred_username"`
EMail string `json:"email"`
Roles []string `json:"roles"`
Roles []string `json:"roles,omitempty"`
Groups []string `json:"groups,omitempty"`
}

func (g *GenericOIDCClaims) Username() string {
Expand All @@ -30,6 +31,14 @@ func (g *GenericOIDCClaims) Username() string {
return g.Name
}

// Returns Roles and falls back to Groups if not set.
func (g *GenericOIDCClaims) Memberships() []string {
if len(g.Roles) != 0 {
return g.Roles
}
return g.Groups
}

// GenericOIDC is Token Validator and UserGetter for Tokens issued by generic OIDC-Providers.
type GenericOIDC struct {
issuerConfig *IssuerConfig
Expand Down Expand Up @@ -154,7 +163,7 @@ func DefaultGenericUserExtractor(ic *IssuerConfig, claims *GenericOIDCClaims) (*
return nil, errors.New("claims is nil")
}
var grps []ResourceAccess
for _, g := range claims.Roles {
for _, g := range claims.Memberships() {
grps = append(grps, ResourceAccess(g))
}

Expand Down