Skip to content

Commit

Permalink
idp/oauth: update processing of cognito claims
Browse files Browse the repository at this point in the history
  • Loading branch information
greenpau committed Dec 2, 2023
1 parent 923da84 commit 8eb4bfb
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions pkg/idp/oauth/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,27 @@ func (b *IdentityProvider) validateAccessToken(state string, data map[string]int
case "cognito":
if v, exists := data["id_token"]; exists {
if tp, err := kms.ParsePayloadFromToken(v.(string)); err == nil {
roles := []string{}
for k, val := range tp {
switch k {
case "custom:roles":
roles := []string{}
for _, roleName := range strings.Split(val.(string), "|") {
roles = append(roles, roleName)
case "custom:roles", "cognito:groups", "cognito:roles":
switch values := v.(type) {
case string:
if k == "custom:roles" {
for _, roleName := range strings.Split(val.(string), "|") {
roles = append(roles, roleName)
}
} else {
roles = append(roles, values)
}
case []interface{}:
for _, value := range values {
switch roleName := value.(type) {
case string:
roles = append(roles, roleName)
}
}
}
m["roles"] = roles
case "custom:timezone":
m["timezone"] = val.(string)
case "cognito:username":
Expand All @@ -135,6 +148,9 @@ func (b *IdentityProvider) validateAccessToken(state string, data map[string]int
m["timezone"] = val.(string)
}
}
if len(roles) > 0 {
m["roles"] = roles
}
}
}
}
Expand Down

0 comments on commit 8eb4bfb

Please sign in to comment.