Skip to content

Commit

Permalink
modifications on PR. Added a space in the bearer string check so that…
Browse files Browse the repository at this point in the history
… we unexpectly dont experience an base64url encoding because bearer is technically part of a valid endcoding, we think. Also moved it into a failed decoding to get a better feedback for the developer, but not do unessecary amount of string checks
  • Loading branch information
vongohren committed Dec 22, 2015
1 parent 1f970af commit 57b1269
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 3 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ 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}
}
return token, &ValidationError{err: err.Error(), Errors: ValidationErrorMalformed}
}
if err = json.Unmarshal(headerBytes, &token.Header); err != nil {
Expand Down
3 changes: 0 additions & 3 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ func (t *Token) SigningString() (string, error) {
// keyFunc will receive the parsed token and should return the key for validating.
// If everything is kosher, err will be nil
func Parse(tokenString string, keyFunc Keyfunc) (*Token, error) {
if strings.Contains(strings.ToLower(tokenString), "bearer") {
return nil, &ValidationError{err: "tokenstring should not contain bearer", Errors: ValidationErrorMalformed}
}
return new(Parser).Parse(tokenString, keyFunc)
}

Expand Down

0 comments on commit 57b1269

Please sign in to comment.