jwt/request/request.go

25 lines
830 B
Go
Raw Normal View History

2016-01-15 01:09:27 +03:00
package request
import (
"github.com/dgrijalva/jwt-go"
"net/http"
)
2016-01-15 01:09:27 +03:00
// Try to find the token in an http.Request.
// 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, extractor Extractor, keyFunc jwt.Keyfunc) (token *jwt.Token, err error) {
return ParseFromRequestWithClaims(req, extractor, jwt.MapClaims{}, keyFunc)
}
2016-01-15 01:09:27 +03:00
func ParseFromRequestWithClaims(req *http.Request, extractor Extractor, claims jwt.Claims, keyFunc jwt.Keyfunc) (token *jwt.Token, err error) {
// Extract token from request
tokStr, err := extractor.ExtractToken(req)
if err != nil {
return nil, err
2016-01-15 01:09:27 +03:00
}
return jwt.ParseWithClaims(tokStr, claims, keyFunc)
2016-01-15 01:09:27 +03:00
}