mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 12:59:31 +00:00
Upgraded from 99c19923, branch release-3.0. This required fetching or upgrading the following: * k8s.io/api to kubernetes-1.9.1 * k8s.io/apimachinery to kubernetes-1.9.1 * github.com/juju/ratelimit to 1.0.1 * github.com/spf13/pflag to 4c012f6d Also, update Scope's imports/function calls to be compatible with the new client.
25 lines
926 B
Go
25 lines
926 B
Go
package request
|
|
|
|
import (
|
|
"github.com/dgrijalva/jwt-go"
|
|
"net/http"
|
|
)
|
|
|
|
// Extract and parse a JWT token from an HTTP request.
|
|
// This behaves the same as Parse, but accepts a request and an extractor
|
|
// instead of a token string. The Extractor interface allows you to define
|
|
// the logic for extracting a token. Several useful implementations are provided.
|
|
func ParseFromRequest(req *http.Request, extractor Extractor, keyFunc jwt.Keyfunc) (token *jwt.Token, err error) {
|
|
return ParseFromRequestWithClaims(req, extractor, jwt.MapClaims{}, keyFunc)
|
|
}
|
|
|
|
// ParseFromRequest but with custom Claims type
|
|
func ParseFromRequestWithClaims(req *http.Request, extractor Extractor, claims jwt.Claims, keyFunc jwt.Keyfunc) (token *jwt.Token, err error) {
|
|
// Extract token from request
|
|
if tokStr, err := extractor.ExtractToken(req); err == nil {
|
|
return jwt.ParseWithClaims(tokStr, claims, keyFunc)
|
|
} else {
|
|
return nil, err
|
|
}
|
|
}
|