Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
Merge f577d10 into 5c87222
Browse files Browse the repository at this point in the history
  • Loading branch information
leobrines committed Nov 19, 2020
2 parents 5c87222 + f577d10 commit bd0076d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
10 changes: 8 additions & 2 deletions jwt/jwt.go
Expand Up @@ -137,8 +137,14 @@ func ParseSignedAndEncrypted(s string) (*NestedJSONWebToken, error) {
}

func tryJWKS(headers []jose.Header, key interface{}) interface{} {
jwks, ok := key.(*jose.JSONWebKeySet)
if !ok {
var jwks jose.JSONWebKeySet

switch jwksType := key.(type) {
case *jose.JSONWebKeySet:
jwks = *jwksType
case jose.JSONWebKeySet:
jwks = jwksType
default:
return key
}

Expand Down
17 changes: 12 additions & 5 deletions jwt/jwt_test.go
Expand Up @@ -81,12 +81,19 @@ func TestDecodeTokenWithJWKS(t *testing.T) {
tok, err := ParseSigned(rsaSignedTokenWithKid)
if assert.NoError(t, err, "Error parsing signed token.") {
cl := make(map[string]interface{})
expected := map[string]interface{}{
"sub": "subject",
"iss": "issuer",
"scopes": []interface{}{"s1", "s2"},
}

if assert.NoError(t, tok.Claims(jwks, &cl)) {
assert.Equal(t, map[string]interface{}{
"sub": "subject",
"iss": "issuer",
"scopes": []interface{}{"s1", "s2"},
}, cl)
assert.Equal(t, expected, cl)
}

cl = make(map[string]interface{})
if assert.NoError(t, tok.Claims(*jwks, &cl)) {
assert.Equal(t, expected, cl)
}
}
}
Expand Down

0 comments on commit bd0076d

Please sign in to comment.