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

OIDC: fallback to "email" if IDP doesn't provide "preferred_username" claim #2314

Merged
merged 1 commit into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions changelog/unreleased/user-claim-fallback.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: OIDC: fallback if IDP doesn't provide "preferred_username" claim

Some IDPs don't support the "preferred_username" claim. Fallback to the
"email" claim in that case.

https://github.com/cs3org/reva/pull/2314
14 changes: 11 additions & 3 deletions pkg/auth/manager/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,16 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)
return nil, nil, fmt.Errorf("no \"email\" attribute found in userinfo: maybe the client did not request the oidc \"email\"-scope")
}

if claims["preferred_username"] == nil || claims["name"] == nil {
return nil, nil, fmt.Errorf("no \"preferred_username\" or \"name\" attribute found in userinfo: maybe the client did not request the oidc \"profile\"-scope")
userClaim := "preferred_username"
if claims["preferred_username"] == nil {
if claims["email"] != nil {
userClaim = "email"
} else {
return nil, nil, fmt.Errorf("no \"preferred_username\" and \"email\" attribute found in userinfo: maybe the client did not request the oidc \"profile\"-scope")
}
}
if claims["name"] == nil {
return nil, nil, fmt.Errorf("no \"name\" attribute found in userinfo: maybe the client did not request the oidc \"profile\"-scope")
}

var uid, gid float64
Expand Down Expand Up @@ -168,7 +176,7 @@ func (am *mgr) Authenticate(ctx context.Context, clientID, clientSecret string)

u := &user.User{
Id: userID,
Username: claims["preferred_username"].(string),
Username: claims[userClaim].(string),
// TODO(labkode) if we can get groups from the claim we need to give the possibility
// to the admin to choose what claim provides the groups.
// TODO(labkode) ... use all claims from oidc?
Expand Down