Documentation
¶
Index ¶
- Constants
- func ClaimsToContext(ctx context.Context, claims Claims) context.Context
- func ClaimsToContextMiddleware(handler http.Handler, header string, idpKey interface{}) http.Handler
- func CreateToken(claims Claims, key interface{}) (string, error)
- func GetTokenFromRequest(r *http.Request, header string) (prefix string, token string, err error)
- func LoadPrivateKey(keyFile string) (interface{}, error)
- func LoadPublicKey(keyFile string) (interface{}, error)
- func ParsePrivateKey(data []byte) (interface{}, error)
- func ParsePublicKey(data []byte) (interface{}, error)
- func RequireClaim(handler http.Handler, claimKey, expectedClaimValue string) http.Handler
- type Claims
- func ClaimsFromContext(ctx context.Context) Claims
- func GetClaimsFromRequest(r *http.Request, header string) (prefix string, claims Claims, err error)
- func GetClaimsFromRequestWithValidation(r *http.Request, header string, key interface{}) (prefix string, claims Claims, err error)
- func GetUnvalidatedClaims(tokenString string) (claims Claims, err error)
- func ValidateToken(tokenString string, key interface{}) (Claims, error)
Constants ¶
const ( // AuthorizationHeader is the constant string used to get the Authorization // headers AuthorizationHeader = "Authorization" )
Variables ¶
This section is empty.
Functions ¶
func ClaimsToContext ¶ added in v0.2.1
ClaimsToContext stores claims in a context
func ClaimsToContextMiddleware ¶ added in v0.2.1
func ClaimsToContextMiddleware(handler http.Handler, header string, idpKey interface{}) http.Handler
ClaimsToContextMiddleware is a http middleware which parses and validates a jwt from the authorization header and stores the claims in the requests context before calling the next handler.
func CreateToken ¶
CreateToken takes some claims and a private key (either rsa or ec) and returns a signed json web token
func GetTokenFromRequest ¶
GetTokenFromRequest takes the first Authorization header or `token` GET pararm , then extract the token prefix and json web token
func LoadPrivateKey ¶
LoadPrivateKey loads a PEM encoded private key (either rsa or ec)
func LoadPublicKey ¶
LoadPublicKey loads a PEM encoded public key (either rsa or ec)
func ParsePrivateKey ¶
ParsePrivateKey parses a pem encoded private key (rsa or ecdsa based)
func ParsePublicKey ¶
ParsePublicKey parses a pem encoded public key (rsa or ecdsa based)
Types ¶
type Claims ¶
type Claims map[string]interface{}
Claims is a map of string->something containing the meta infos associated with a token
func ClaimsFromContext ¶ added in v0.2.1
ClaimsFromContext retrieves the requests claims from a context
func GetClaimsFromRequest ¶
GetClaimsFromRequest extracts the token from a request, returning the claims without validating the token. This should only be used in situations where you can already trust or if you are simply logging the claim information.
func GetClaimsFromRequestWithValidation ¶ added in v0.2.0
func GetClaimsFromRequestWithValidation(r *http.Request, header string, key interface{}) (prefix string, claims Claims, err error)
GetClaimsFromRequestWithValidation extracts and validates the token from a request, returning the claims
func GetUnvalidatedClaims ¶ added in v0.2.0
GetUnvalidatedClaims extracts the token claims without validating the token
func ValidateToken ¶
ValidateToken checks the signature of the token with a given public key and returns the associated claims