try to get the access_token from the request params as well as the header

This commit is contained in:
Dave Grijalva 2012-07-07 12:38:18 -07:00
parent 224f53452d
commit 71677efc53
1 changed files with 9 additions and 1 deletions

10
jwt.go
View File

@ -136,7 +136,9 @@ func Parse(tokenString string, keyFunc Keyfunc) (token *Token, err error) {
} }
// Try to find the token in an http.Request. // 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) { func ParseFromRequest(req *http.Request, keyFunc Keyfunc) (token *Token, err error) {
// Look for an Authorization header // 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.") return nil, errors.New("No token present in request.")
} }