jwt

package
v5.7.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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"}
)
View Source
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

func Audience(token string) string

Audience The "aud" (audience) claim identifies the audience that the JWT is intended for.

func BearerAuth

func BearerAuth(r *http.Request) (token string, ok bool)

BearerAuth returns the token provided in the request's Authorization header, if the request uses HTTP Bearer Authentication.

func Identifier

func Identifier(token string) string

Identifier the "iss" (issuer) claim identifies the principal that issued the JWT.

func Jti

func Jti(token string) string

Jti The "jti" (JWT ID) claim provides a unique identifier for the JWT.

func LoadPrivateKey

func LoadPrivateKey(path string) (*rsa.PrivateKey, error)

LoadPrivateKey loads a private key from PEM encoded data.

func LoadPublicKey

func LoadPublicKey(path string) (*rsa.PublicKey, error)

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 NewToken

func NewToken(ctx context.Context, cs *ClaimSet) (string, error)

NewToken returns a JWT token signed with the given RSA private key.

func Principal

func Principal(token string) string

Principal The "prn" (principal) claim identifies the subject of the JWT.

func PrivateKeyFromContext

func PrivateKeyFromContext(ctx context.Context) (p *rsa.PrivateKey, ok bool)

PrivateKeyFromContext returns private key pointer from a context

func PublicKeyFromContext

func PublicKeyFromContext(ctx context.Context) (p *rsa.PublicKey, ok bool)

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 Scope

func Scope(token string) string

Scope space-delimited list of the permissions the application requests.

func Verify

func Verify(ctx context.Context, token string) error

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

Types

type ClaimSet

type ClaimSet struct {
	Identifier, Audience, Scope, Jti, Principal string
	Expiration                                  int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL