From ca46641b15f1c6132c47599e44af5851fd684e4f Mon Sep 17 00:00:00 2001 From: Snorre lothar von Gohren Edwin Date: Wed, 23 Dec 2015 09:43:00 +0100 Subject: [PATCH] PR updated, faster string method and more reasonable message feedback --- parser.go | 4 ++-- token.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/parser.go b/parser.go index 1659ad2..a078404 100644 --- a/parser.go +++ b/parser.go @@ -26,8 +26,8 @@ func (p *Parser) Parse(tokenString string, keyFunc Keyfunc) (*Token, error) { // parse Header var headerBytes []byte if headerBytes, err = DecodeSegment(parts[0]); err != nil { - if strings.Contains(strings.ToLower(tokenString), "bearer ") { - return token, &ValidationError{err: "tokenstring should not contain bearer", Errors: ValidationErrorMalformed} + if strings.HasPrefix(strings.ToLower(tokenString), "bearer ") { + return token, &ValidationError{err: "tokenstring should not contain 'bearer '", Errors: ValidationErrorMalformed} } return token, &ValidationError{err: err.Error(), Errors: ValidationErrorMalformed} } diff --git a/token.go b/token.go index 1cf267d..fde0116 100644 --- a/token.go +++ b/token.go @@ -97,7 +97,7 @@ func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err err if ah := req.Header.Get("Authorization"); ah != "" { // Should be a bearer token if len(ah) > 6 && strings.ToUpper(ah[0:7]) == "BEARER " { - return Parse(ah[7:], keyFunc) + return Parse(ah, keyFunc) } }