Skip to content

Commit 811046c

Browse files
authored
auth/oidc: support slice-typed extra claims via overlap match (#1238)
Closes #988. Direct `actualValue != expectedValue` fails when the token claim is an array (groups, roles, scp, aud). Switch to a slice-aware any-of overlap so OIDC list claims are validated correctly.
1 parent f3308d1 commit 811046c

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

  • internal/api/handlers/v0/auth

internal/api/handlers/v0/auth/oidc.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (h *OIDCHandler) validateExtraClaims(claims *OIDCClaims) error {
224224
return fmt.Errorf("claim validation failed: required claim %s not found", key)
225225
}
226226

227-
if actualValue != expectedValue {
227+
if !claimMatches(actualValue, expectedValue) {
228228
return fmt.Errorf("claim validation failed: %s expected %v, got %v", key, expectedValue, actualValue)
229229
}
230230
}
@@ -233,6 +233,38 @@ func (h *OIDCHandler) validateExtraClaims(claims *OIDCClaims) error {
233233
return nil
234234
}
235235

236+
// claimMatches reports whether a claim value satisfies the expected configuration.
237+
// Both sides may be a scalar or a slice; for slice-typed claims (groups, roles, scp,
238+
// aud, etc.) any single overlap is treated as a match, mirroring how OIDC consumers
239+
// normally interpret list claims.
240+
func claimMatches(actual, expected any) bool {
241+
actualList := toAnySlice(actual)
242+
expectedList := toAnySlice(expected)
243+
for _, e := range expectedList {
244+
for _, a := range actualList {
245+
if a == e {
246+
return true
247+
}
248+
}
249+
}
250+
return false
251+
}
252+
253+
func toAnySlice(v any) []any {
254+
switch s := v.(type) {
255+
case []any:
256+
return s
257+
case []string:
258+
out := make([]any, len(s))
259+
for i, x := range s {
260+
out[i] = x
261+
}
262+
return out
263+
default:
264+
return []any{v}
265+
}
266+
}
267+
236268
// buildPermissions builds permissions based on OIDC claims and configuration
237269
func (h *OIDCHandler) buildPermissions(_ *OIDCClaims) []auth.Permission {
238270
var permissions []auth.Permission

0 commit comments

Comments
 (0)