auth

package module
v0.0.0-...-68228b3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromAuthHeader

func FromAuthHeader(r *http.Request) (string, error)

FromAuthHeader is a "TokenExtractor" that takes a give request and extracts the JWT token from the Authorization header.

func JWTFromContext

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

func NewJWTWithClaims

func NewJWTWithClaims(claims jwt.MapClaims, key *rsa.PrivateKey) (string, error)

func OnError

func OnError(w http.ResponseWriter, r *http.Request, err string)

Types

type JWTMiddleware

type JWTMiddleware struct {
	Options JWTOptions
}

func NewJWTMiddleware

func NewJWTMiddleware(options ...JWTOptions) *JWTMiddleware

func (*JWTMiddleware) CheckJWT

func (m *JWTMiddleware) CheckJWT(w http.ResponseWriter, r *http.Request) error

func (*JWTMiddleware) Handler

func (m *JWTMiddleware) Handler() func(http.Handler) http.Handler

type JWTOptions

type JWTOptions struct {
	ValidationKeyGetter jwt.Keyfunc
	// Whether the lack of credentials should throw an error
	CredentialsOptional bool
	// Function to be called when there's an error validating the token
	ErrorHandler errorHandler
	// A function to extract the token from the request
	Extractor TokenExtractor
	// When set, all requests with the OPTIONS method will use authentication
	EnableAuthOnOptions bool
	// When set, the middelware verifies that tokens are signed with the specific signing algorithm
	// If the signing method is not constant the ValidationKeyGetter callback can be used to implement additional checks
	// Important to avoid security issues described here: https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries/
	SigningMethod jwt.SigningMethod
}

type TokenExtractor

type TokenExtractor func(r *http.Request) (string, error)

TokenExtractor is a function that takes a request as input and returns either a token or an error. An error should only be returned if an attempt to specify a token was found, but the information was somehow incorrectly formed. In the case where a token is simply not present, this should not be treated as an error. An empty string should be returned in that case.

func FromFirst

func FromFirst(extractors ...TokenExtractor) TokenExtractor

FromFirst returns a function that runs multiple token extractors and takes the first token it finds

func FromParameter

func FromParameter(param string) TokenExtractor

FromParameter returns a function that extracts the token from the specified query string parameter

Jump to

Keyboard shortcuts

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