PR updated, faster string method and more reasonable message feedback

This commit is contained in:
Snorre lothar von Gohren Edwin 2015-12-23 09:43:00 +01:00
parent 57b1269c41
commit ca46641b15
2 changed files with 3 additions and 3 deletions

View File

@ -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}
}

View File

@ -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)
}
}