Documentation ¶
Index ¶
- Variables
- func Audience(token string) string
- func BearerAuth(r *http.Request) (token string, ok bool)
- 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 Verify(ctx context.Context, token string) error
- 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"} )
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 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