mirror of https://github.com/golang-jwt/jwt.git
try to get the access_token from the request params as well as the header
This commit is contained in:
parent
224f53452d
commit
71677efc53
10
jwt.go
10
jwt.go
|
@ -136,7 +136,9 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) {
|
|||
}
|
||||
|
||||
// Try to find the token in an http.Request.
|
||||
// Currently, it only looks in the Authorization header
|
||||
// This method will call ParseMultipartForm if there's no token in the header.
|
||||
// Currently, it looks in the Authorization header as well as
|
||||
// looking for an 'access_token' request parameter in req.Form.
|
||||
func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err error) {
|
||||
|
||||
// Look for an Authorization header
|
||||
|
@ -147,6 +149,12 @@ func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err err
|
|||
}
|
||||
}
|
||||
|
||||
// Look for "access_token" parameter
|
||||
req.ParseMultipartForm(10e9)
|
||||
if tokStr := req.Form.Get("access_token"); tokStr != "" {
|
||||
return Parse(tokStr, keyFunc)
|
||||
}
|
||||
|
||||
return nil, errors.New("No token present in request.")
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue