forked from mirror/jwt
fixes
This commit is contained in:
parent
0a26d2272f
commit
224f53452d
4
jwt.go
4
jwt.go
|
@ -33,6 +33,7 @@ func New(method SigningMethod) *Token {
|
||||||
"alg": method.Alg(),
|
"alg": method.Alg(),
|
||||||
},
|
},
|
||||||
Claims: make(map[string]interface{}),
|
Claims: make(map[string]interface{}),
|
||||||
|
Method: method,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +102,8 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) {
|
||||||
|
|
||||||
// Lookup signature method
|
// Lookup signature method
|
||||||
if method, ok := token.Header["alg"].(string); ok {
|
if method, ok := token.Header["alg"].(string); ok {
|
||||||
if token.Method, err = GetSigningMethod(method); err != nil {
|
if token.Method = GetSigningMethod(method); token.Method == nil {
|
||||||
|
err = errors.New("Signing method (alg) is unavailable.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package jwt
|
package jwt
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
var signingMethods = map[string]func() SigningMethod{}
|
var signingMethods = map[string]func() SigningMethod{}
|
||||||
|
|
||||||
// Signing method
|
// Signing method
|
||||||
|
@ -21,11 +16,9 @@ func RegisterSigningMethod(alg string, f func() SigningMethod) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a signing method from an "alg" string
|
// Get a signing method from an "alg" string
|
||||||
func GetSigningMethod(alg string) (method SigningMethod, err error) {
|
func GetSigningMethod(alg string) (method SigningMethod) {
|
||||||
if methodF, ok := signingMethods[alg]; ok {
|
if methodF, ok := signingMethods[alg]; ok {
|
||||||
method = methodF()
|
method = methodF()
|
||||||
} else {
|
|
||||||
err = errors.New(fmt.Sprintf("Invalid signing method (alg): %v", method))
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue