auth

package
v2.0.0-...-071b5fc Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ClaimsContext string = "claims"

Variables

View Source
var ErrNoToken = errors.New("jwt: no token could be extracted and Options.RequireToken is true")

Functions

func ExtractTokenFromHeader

func ExtractTokenFromHeader(r *http.Request) (token string, err error)

ExtractTokenFromHeader extracts a JWT out of the authorization header of an HTTP request

func IssueToken

func IssueToken(key []byte, subject string, expiry time.Time) (token *oauth2.Token, err error)

IssueToken is a little helper that issues tokens for a specified key, subject and expiry time

Types

type ErrorHandlerFunc

type ErrorHandlerFunc func(err error, w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

ErrorHandlerFunc defines a function which is called if an error occured during the extraction of a token

type JWTHandler

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

func NewHandler

func NewHandler(Options Options) *JWTHandler

NewHandler creates a new instance of the JWT handler

func (JWTHandler) AuthRequired

func (h JWTHandler) AuthRequired(c *gin.Context)

AuthRequired is a middleware for gin-gonic

type Options

type Options struct {
	TokenExtractor TokenExtractorFunc
	ErrorHandler   ErrorHandlerFunc
	JWTKeySupplier jwt.Keyfunc
	JWTClaims      jwt.Claims
	RequireToken   bool
}
var DefaultOptions Options

type TokenExtractorFunc

type TokenExtractorFunc func(r *http.Request) (token string, err error)

TokenExtractorFunc defines a function which extracts a token out of an HTTP request

func ExtractFromFirstAvailable

func ExtractFromFirstAvailable(extractors ...TokenExtractorFunc) TokenExtractorFunc

ExtractFromFirstAvailable extracts the token out of the specified extractors. The first token that is found will be returned

func ExtractTokenFromCookie

func ExtractTokenFromCookie(cookie string) TokenExtractorFunc

ExtractTokenFromCookie extracts a JWT out of an HTTP cookie

Jump to

Keyboard shortcuts

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