jwt

package module
v0.0.0-...-32569a1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(auth *Auth, o Options) error

New constructs a new Auth instance with supplied options.

Types

type Auth

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

Auth is a middleware that provides jwt based authentication.

func (*Auth) GrabTokenClaims

func (a *Auth) GrabTokenClaims(r *http.Request) (ClaimsType, error)

GrabTokenClaims : extract the claims from the request note: we always grab from the authToken

func (*Auth) Handler

func (a *Auth) Handler(h http.Handler) http.Handler

Handler implements the http.HandlerFunc for integration with the standard net/http lib.

func (*Auth) HandlerFunc

func (a *Auth) HandlerFunc(fn http.HandlerFunc) http.Handler

HandlerFunc works identically to Handler, but takes a HandlerFunc instead of a Handler.

func (*Auth) HandlerFuncWithNext

func (a *Auth) HandlerFuncWithNext(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

HandlerFuncWithNext is a special implementation for Negroni, but could be used elsewhere.

func (*Auth) IssueNewTokens

func (a *Auth) IssueNewTokens(w http.ResponseWriter, claims *ClaimsType) error

IssueNewTokens : and also modify create refresh and auth token functions!

func (*Auth) NullifyTokens

func (a *Auth) NullifyTokens(w http.ResponseWriter, r *http.Request) error

NullifyTokens : invalidate tokens note @adam-hanna: what if there are no credentials in the request?

func (*Auth) Process

func (a *Auth) Process(w http.ResponseWriter, r *http.Request) *jwtError

Process runs the actual checks and returns an error if the middleware chain should stop.

func (*Auth) SetCheckTokenIdFunction

func (a *Auth) SetCheckTokenIdFunction(checker TokenIdChecker)

SetCheckTokenIdFunction : set the function which checks token id's

func (*Auth) SetErrorHandler

func (a *Auth) SetErrorHandler(handler http.Handler)

SetErrorHandler : add methods to allow the changing of default functions

func (*Auth) SetRevokeTokenFunction

func (a *Auth) SetRevokeTokenFunction(revoker TokenRevoker)

SetRevokeTokenFunction : set the function which revokes a token

func (*Auth) SetUnauthorizedHandler

func (a *Auth) SetUnauthorizedHandler(handler http.Handler)

SetUnauthorizedHandler : set the 401 handler

type ClaimsType

type ClaimsType struct {
	// Standard claims are the standard jwt claims from the ietf standard
	// https://tools.ietf.org/html/rfc7519
	jwtGo.StandardClaims
	Csrf         string
	CustomClaims map[string]interface{}
}

ClaimsType : holds the claims encoded in the jwt

type Options

type Options struct {
	SigningMethodString   string
	PrivateKeyLocation    string
	PublicKeyLocation     string
	HMACKey               []byte
	VerifyOnlyServer      bool
	BearerTokens          bool
	RefreshTokenValidTime time.Duration
	AuthTokenValidTime    time.Duration
	AuthTokenName         string
	RefreshTokenName      string
	CSRFTokenName         string
	Debug                 bool
	IsDevEnv              bool
	Logger                logger
	SameSite              http.SameSite
	Secure                bool
}

Options is a struct for specifying configuration options

type TokenIdChecker

type TokenIdChecker func(tokenId string) bool

TokenIdChecker : a type to check tokens

type TokenRevoker

type TokenRevoker func(tokenId string) error

TokenRevoker : a type to revoke tokens

Jump to

Keyboard shortcuts

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