Skip to content

Commit

Permalink
Ignore case-sensitivity for "Bearer"
Browse files Browse the repository at this point in the history
  • Loading branch information
WhyNotHugo committed Aug 15, 2022
1 parent 781c8bd commit 09600b6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion request/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ type BearerExtractor struct{}

func (e BearerExtractor) ExtractToken(req *http.Request) (string, error) {
tokenHeader := req.Header.Get("Authorization")
if tokenHeader == "" || !strings.HasPrefix(tokenHeader, "Bearer ") {
// The usual convention is for "Bearer" to be title-cased. However,
// there's no strict rule around this, and it's best to follow the
// robustness principle here.
if tokenHeader == "" || !strings.HasPrefix(strings.ToLower(tokenHeader), "bearer ") {
return "", ErrNoTokenInRequest
}
return strings.TrimPrefix(tokenHeader, "Bearer "), nil
Expand Down

0 comments on commit 09600b6

Please sign in to comment.