mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 19:00:46 +00:00
Merge fb0bcbc4b7 into 06b23b4293
This commit is contained in:
commit
8f0e3bae75
2 changed files with 13 additions and 4 deletions
|
|
@ -47,8 +47,10 @@ func (handler *jwtHandler) ServeHTTP(out http.ResponseWriter, r *http.Request) {
|
|||
strToken string
|
||||
claims jwt.RegisteredClaims
|
||||
)
|
||||
// RFC 7235: authentication schemes are case-insensitive. Match with EqualFold
|
||||
// and slice off the scheme prefix (do not use TrimPrefix, which is case-sensitive).
|
||||
if auth := r.Header.Get("Authorization"); len(auth) >= 7 && strings.EqualFold(auth[:7], "bearer ") {
|
||||
strToken = strings.TrimPrefix(auth, "Bearer ")
|
||||
strToken = auth[7:]
|
||||
}
|
||||
if len(strToken) == 0 {
|
||||
http.Error(out, "missing token", http.StatusUnauthorized)
|
||||
|
|
|
|||
|
|
@ -371,6 +371,16 @@ func TestJWT(t *testing.T) {
|
|||
"bar": "baz",
|
||||
}))
|
||||
},
|
||||
// RFC 7235: authentication scheme is case-insensitive.
|
||||
func() string {
|
||||
return fmt.Sprintf("bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
func() string {
|
||||
return fmt.Sprintf("BEARER %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
func() string {
|
||||
return fmt.Sprintf("bEaReR %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
}
|
||||
for i, tokenFn := range expOk {
|
||||
token := tokenFn()
|
||||
|
|
@ -421,9 +431,6 @@ func TestJWT(t *testing.T) {
|
|||
func() string {
|
||||
return fmt.Sprintf("Bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
func() string {
|
||||
return fmt.Sprintf("bearer %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
func() string {
|
||||
return fmt.Sprintf("Bearer: %v", issueToken(secret, nil, testClaim{"iat": time.Now().Unix()}))
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue