forked from mirror/jwt
PR updated, faster string method and more reasonable message feedback
This commit is contained in:
parent
57b1269c41
commit
ca46641b15
|
@ -26,8 +26,8 @@ func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
|
||||||
// parse Header
|
// parse Header
|
||||||
var headerBytes []byte
|
var headerBytes []byte
|
||||||
if headerBytes, err = DecodeSegment(parts[0]); err != nil {
|
if headerBytes, err = DecodeSegment(parts[0]); err != nil {
|
||||||
if strings.Contains(strings.ToLower(tokenString), "bearer ") {
|
if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") {
|
||||||
return token, &ValidationError{err: "tokenstring should not contain bearer", Errors: ValidationErrorMalformed}
|
return token, &ValidationError{err: "tokenstring should not contain 'bearer '", Errors: ValidationErrorMalformed}
|
||||||
}
|
}
|
||||||
return token, &ValidationError{err: err.Error(), Errors: ValidationErrorMalformed}
|
return token, &ValidationError{err: err.Error(), Errors: ValidationErrorMalformed}
|
||||||
}
|
}
|
||||||
|
|
2
token.go
2
token.go
|
@ -97,7 +97,7 @@ func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err err
|
||||||
if ah := req.Header.Get("Authorization"); ah != "" {
|
if ah := req.Header.Get("Authorization"); ah != "" {
|
||||||
// Should be a bearer token
|
// Should be a bearer token
|
||||||
if len(ah) > 6 && strings.ToUpper(ah[0:7]) == "BEARER " {
|
if len(ah) > 6 && strings.ToUpper(ah[0:7]) == "BEARER " {
|
||||||
return Parse(ah[7:], keyFunc)
|
return Parse(ah, keyFunc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue