Documentation
¶
Index ¶
- Variables
- func Audience(token string) string
- func BearerAuth(r *http.Request) (token string, ok bool)
- func BearerTokenStreamServerInterceptor() grpc.StreamClientInterceptor
- func BearerTokenUnaryServerInterceptor() grpc.UnaryServerInterceptor
- func Identifier(token string) string
- func Jti(token string) string
- func LoadPrivateKey(path string) (*rsa.PrivateKey, error)
- func LoadPublicKey(path string) (*rsa.PublicKey, error)
- func Middleware(a *rsa.PublicKey, b *rsa.PrivateKey) router.Middleware
- func NewToken(ctx context.Context, cs *ClaimSet) (string, error)
- func Principal(token string) string
- func PrivateKeyFromContext(ctx context.Context) (p *rsa.PrivateKey, ok bool)
- func PublicKeyFromContext(ctx context.Context) (p *rsa.PublicKey, ok bool)
- func RsaUnaryServerInterceptor(a *rsa.PublicKey, b *rsa.PrivateKey) grpc.UnaryServerInterceptor
- func Scope(token string) string
- func TokenFromContext(ctx context.Context) (p string, ok bool)
- func Verify(ctx context.Context, token string) error
- func WrapBearerToken(h router.HandlerFunc) router.HandlerFunc
- type ClaimSet
Constants ¶
This section is empty.
Variables ¶
var ( // PublicKeyContextKey is a context key. It can be used in HTTP / GRPC // handlers with context.WithValue to access the server that // started the handler. The associated value will be of type *rsa.PublicKey. PublicKeyContextKey = &contextKey{"public-key"} // PrivateKeyContextKey is a context key. It can be used in HTTP / GRPC // handlers with context.WithValue to access the server that // started the handler. The associated value will be of type *rsa.PublicKey. PrivateKeyContextKey = &contextKey{"private-key"} // TokenContextKey is a context key. It can be used in HTTP / GRPC // handlers with context.WithValue to access the server that // started the handler. The associated value will be of type string. TokenContextKey = &contextKey{"token-key"} )
var ( ErrExpiredToken = errors.New("token has expired") ErrInvalidAudience = errors.New("token has invalid audience") ErrInvalidIdentifier = errors.New("token has invalid identifier") ErrPrivateKeyNotAvailable = errors.New("private key not available in context") ErrPublicKeyNotAvailable = errors.New("public key not available in context") )
Functions ¶
func Audience ¶
Audience The "aud" (audience) claim identifies the audience that the JWT is intended for.
func BearerAuth ¶
BearerAuth returns the token provided in the request's Authorization header, if the request uses HTTP Bearer Authentication.
func BearerTokenStreamServerInterceptor ¶ added in v6.2.0
func BearerTokenStreamServerInterceptor() grpc.StreamClientInterceptor
BearerTokenStreamServerInterceptor makes bearer token available in grpc context
func BearerTokenUnaryServerInterceptor ¶ added in v6.2.0
func BearerTokenUnaryServerInterceptor() grpc.UnaryServerInterceptor
BearerTokenUnaryServerInterceptor makes bearer token available in grpc context
func Identifier ¶
Identifier the "iss" (issuer) claim identifies the principal that issued the JWT.
func LoadPrivateKey ¶
func LoadPrivateKey(path string) (*rsa.PrivateKey, error)
LoadPrivateKey loads a private key from PEM encoded data.
func LoadPublicKey ¶
LoadPublicKey loads a public key from PEM encoded data.
func Middleware ¶
func Middleware(a *rsa.PublicKey, b *rsa.PrivateKey) router.Middleware
Middleware adds *rsa.PublicKey and *rsa.PrivateKey to the context.
func PrivateKeyFromContext ¶
func PrivateKeyFromContext(ctx context.Context) (p *rsa.PrivateKey, ok bool)
PrivateKeyFromContext returns private key pointer from a context
func PublicKeyFromContext ¶
PublicKeyFromContext retuns public key pointer from a context if it exists.
func RsaUnaryServerInterceptor ¶
func RsaUnaryServerInterceptor(a *rsa.PublicKey, b *rsa.PrivateKey) grpc.UnaryServerInterceptor
RsaUnaryServerInterceptor makes rsa public and private keys available in grpc context
func TokenFromContext ¶ added in v6.2.0
TokenFromContext retuns token from a context if it exists.
func Verify ¶
Verify tests whether the provided JWT token's signature was produced by the private key associated with the supplied public key. Also verifies if Token as expired
func WrapBearerToken ¶ added in v6.2.0
func WrapBearerToken(h router.HandlerFunc) router.HandlerFunc
WrapBearerToken adds token to the context.