simplejwt

package
v0.0.0-...-4beddfa Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextGetToken

func ContextGetToken(ctx context.Context) (*jwt.Token, error)

ContextGetToken tries to get the token from the context it returns an error if the token is missing or invalid

It DOES NOT validate the token claims or signature That would require the public key and should have been handled by the process that set the token originally

func ContextWithToken

func ContextWithToken(ctx context.Context, token *jwt.Token) context.Context

ContextWithToken adds the given token to the given context

func MustContextGetToken

func MustContextGetToken(ctx context.Context) *jwt.Token

MustContextGetToken parses the token out of the context it will panic if the token is not found

Types

type Issuer

type Issuer struct {
	// contains filtered or unexported fields
}

START ISSUER OMIT Issuer handles JWT issuing

func NewIssuer

func NewIssuer(privateKeyPath string) (*Issuer, error)

NewIssuer creates a new issuer by parsing the given path as a ed25519 private key

func (*Issuer) IssueToken

func (i *Issuer) IssueToken(user string, roles []string) (string, error)

IssueToken issues a new token for the given user with the given roles

type Middleware

type Middleware struct {
	// embed the validator to make token calls cleaner
	Validator
}

Middleware handles all jwt parsing and validation automatically when used

func NewMiddleware

func NewMiddleware(publicKeyPath string) (*Middleware, error)

NewMiddleware creates a new middleware that validates using the given public key file

func (*Middleware) HandleHTTP

func (m *Middleware) HandleHTTP(h http.Handler) http.HandlerFunc

func (*Middleware) UnaryClientInterceptor

func (m *Middleware) UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

func (*Middleware) UnaryServerInterceptor

func (m *Middleware) UnaryServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

START VALIDATOR OMIT Validator does parsing and validation of JWT token

func NewValidator

func NewValidator(publicKeyPath string) (*Validator, error)

NewValidator returns a new validator by parsing the given file path as a ed25519 public key

func (*Validator) GetToken

func (v *Validator) GetToken(tokenString string) (*jwt.Token, error)

GetToken attempts to get a token from the given string it validates both the signature and claim and returns nil and an err if invalid

Jump to

Keyboard shortcuts

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