Skip to content

Commit f9c6649

Browse files
authored
Merge pull request #240 from OvermindDL1/patch-1
Follow the OpenID Connect Audiences spec
2 parents eacfac3 + 58e1316 commit f9c6649

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

providers/openidConnect/openidConnect.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,17 @@ func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error) {
200200
func (p *Provider) validateClaims(claims map[string]interface{}) (time.Time, error) {
201201
audience := getClaimValue(claims, []string{audienceClaim})
202202
if audience != p.ClientKey {
203-
return time.Time{}, errors.New("audience in token does not match client key")
203+
found := false
204+
audiences := getClaimValues(claims, []string{audienceClaim})
205+
for _, aud := range audiences {
206+
if aud == p.ClientKey {
207+
found = true
208+
break
209+
}
210+
}
211+
if !found {
212+
return time.Time{}, errors.New("audience in token does not match client key")
213+
}
204214
}
205215

206216
issuer := getClaimValue(claims, []string{issuerClaim})
@@ -355,6 +365,24 @@ func getClaimValue(data map[string]interface{}, claims []string) string {
355365
return ""
356366
}
357367

368+
func getClaimValues(data map[string]interface{}, claims []string) []string {
369+
var result []string
370+
371+
for _, claim := range claims {
372+
if value, ok := data[claim]; ok {
373+
if stringValues, ok := value.([]interface{}); ok {
374+
for _, stringValue := range stringValues {
375+
if s, ok := stringValue.(string); ok && len(s) > 0 {
376+
result = append(result, s)
377+
}
378+
}
379+
}
380+
}
381+
}
382+
383+
return result
384+
}
385+
358386
// decodeJWT decodes a JSON Web Token into a simple map
359387
// http://openid.net/specs/draft-jones-json-web-token-07.html
360388
func decodeJWT(jwt string) (map[string]interface{}, error) {

0 commit comments

Comments
 (0)