Skip to content

Commit

Permalink
fix: add picture claim key
Browse files Browse the repository at this point in the history
  • Loading branch information
kumo-rn5s committed Jul 5, 2024
1 parent d13a66b commit 126d268
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/oauth/oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const (
listPerPage = 100
)

var usernameKeys = []string{"username", "name", "preferred_username", "cognito:username"}
var avatarUrlKey = []string{"picture", "avatar_url"}

// OAuthClient is a oauth client for OIDC.
type OAuthClient struct {
*oidc.Provider
Expand Down Expand Up @@ -178,8 +181,6 @@ func (c *OAuthClient) decideRole(claims jwt.MapClaims) (role *model.Role, err er
}

func (c *OAuthClient) decideUserInfos(claims jwt.MapClaims) (username, avatarUrl string, err error) {
usernameKeys := []string{"username", "name", "preferred_username", "cognito:username"}
avatarUrlKey := "avatar_url"

username = ""
for _, key := range usernameKeys {
Expand All @@ -198,10 +199,12 @@ func (c *OAuthClient) decideUserInfos(claims jwt.MapClaims) (username, avatarUrl
}

avatarUrl = ""
val, ok := claims[avatarUrlKey]
if ok && val != nil {
if str, ok := val.(string); ok && str != "" {
avatarUrl = str
for _, key := range avatarUrlKey {
val, ok := claims[key]
if ok && val != nil {
if str, ok := val.(string); ok && str != "" {
avatarUrl = str
}
}
}

Expand Down

0 comments on commit 126d268

Please sign in to comment.