Skip to content

Commit

Permalink
fix: jwt kid type assertion bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shaj13 committed Jan 12, 2021
1 parent 2d97a18 commit 14d0164
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion auth/strategies/jwt/token.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jwt

import (
"errors"
"time"

"github.com/dgrijalva/jwt-go/v4"
Expand All @@ -10,6 +11,10 @@ import (

const headerKID = "kid"

// ErrMissingKID is returned by Authenticate Strategy method,
// when failed to retrieve kid from token header.
var ErrMissingKID = errors.New("strategies/jwt: Token missing " + headerKID + "header")

// IssueAccessToken issue jwt access token for the provided user info.
func IssueAccessToken(info auth.Info, s SecretsKeeper, opts ...auth.Option) (string, error) {
return newAccessToken(s, opts...).issue(info)
Expand Down Expand Up @@ -54,7 +59,16 @@ func (at accessToken) parse(tstr string) (*claims, error) {
}

keyFunc := func(jt *jwt.Token) (interface{}, error) {
kid := jt.Header[headerKID].(string)
v, ok := jt.Header[headerKID]
if !ok {
return nil, ErrMissingKID
}

kid, ok := v.(string)
if !ok {
return nil, auth.NewTypeError("strategies/jwt: kid", "str", v)
}

secret, _, err := at.s.Get(kid)
return secret, err
}
Expand Down

0 comments on commit 14d0164

Please sign in to comment.