jwt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2020 License: MIT Imports: 12 Imported by: 0

README

gojwt

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotValidToken  = fmt.Errorf("token is not valid")
	ErrFailedGetClaim = fmt.Errorf("failed to get token claims")
)

Functions

func NewServer

func NewServer(
	srv fasthttp.RequestHandler,
	errorProcessor ErrorProcessor,
	errorCreator ErrorCreator,
	jwtHeaderName string,
	authHeaderScheme []byte,
	verifier Verifier,
	contextTokenStorage ContextTokenStorage,
) fasthttp.RequestHandler

NewServer ...

Types

type ClaimsJWT

type ClaimsJWT struct {
	jwtgo.StandardClaims
	JWT
}

ClaimsJWT ...

type ContextTokenStorage

type ContextTokenStorage interface {
	Set(ctx *fasthttp.RequestCtx, token JWT)
	Get(ctx context.Context) (token JWT, found bool)
}

ContextTokenStorage represents interface for token set and get methods to request context

func NewContextTokenStorage

func NewContextTokenStorage(ctxJWTKey string) ContextTokenStorage

NewContextTokenStorage creates new ContextTokenStorage

type ErrorCreator

type ErrorCreator func(status int, format string, v ...interface{}) error

type ErrorProcessor

type ErrorProcessor interface {
	Encode(ctx context.Context, r *fasthttp.Response, err error)
}

type Generator

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

Generator ...

func NewGenerator

func NewGenerator(privateKey jose.JSONWebKey, expireIn time.Duration, timeFunc func() time.Time) *Generator

NewGenerator ...

func (*Generator) Generate

func (g *Generator) Generate(links ...[]byte) (token []byte, err error)

Generate ...

type JWT

type JWT struct {
	Original []byte   `json:"original"` // contains original jwt
	Links    [][]byte `json:"links"`
}

JWT represents a parsed and verified access token.

type PrivateKeyLoader

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

PrivateKeyLoader ...

func NewPrivateKeyLoader

func NewPrivateKeyLoader(jwkUse string, jwkAlgorithm string, hash crypto.Hash) *PrivateKeyLoader

NewPrivateKeyLoader ...

jwkUse       	= "sig"
jwkAlgorithm 	= "RS256"
hash 			= crypto.SHA256

func (*PrivateKeyLoader) Load

func (p *PrivateKeyLoader) Load(file string) (privateKey jose.JSONWebKey, err error)

Load ...

type PublicKeyLoader

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

PublicKeyLoader ...

func NewPublicKeyLoader

func NewPublicKeyLoader(jwkUse string, jwkAlgorithm string, hash crypto.Hash) *PublicKeyLoader

NewPublicKeyLoader ... example:

jwkUse       	= "sig"
jwkAlgorithm 	= "RS256"
hash 			= crypto.SHA256

func (*PublicKeyLoader) Load

func (p *PublicKeyLoader) Load(file string) (publicKey jose.JSONWebKey, err error)

Load ...

type Server

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

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(ctx *fasthttp.RequestCtx)

type Verifier

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

func NewVerifier

func NewVerifier(key *rsa.PublicKey) *Verifier

NewVerifier creates a new Generator verifier.

func (*Verifier) Verify

func (v *Verifier) Verify(token []byte) (jwt JWT, err error)

Verify parses and verifies an access token string.

Jump to

Keyboard shortcuts

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