auth

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2020 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoTokenInRequest = errors.New("no token present in request")
)

Errors

Functions

func JWTAuthHandler

func JWTAuthHandler(
	signingKey string,
	claimConverter ClaimConverter,
	contextSetter ContextSetter,
	contextGetter ContextGetter,
	opts ...Option,
) gin.HandlerFunc

JWTAuthHandler returns a new JWT authentication Gin Handler Parameters:

  • signingKey - the HMAC JWT token signing key
  • claimConverter - converts the JWT token into a JWT claim object, which will be saved into the request context
  • extractors (optional) - additional token extractors to use besides OAuth2Extractor
  • tokenStore (optional) - checks if the incoming JWT Bearer token's ID is present in this TokenStore (can be nil, which pypasses the check)

Types

type ClaimConverter

type ClaimConverter func(*ScopedClaims) interface{}

ClaimConverter converts claims to another domain object for saving into Context

type ContextGetter added in v0.2.0

type ContextGetter func(c context.Context) interface{}

ContextGetter gets the resolved (and converted) claims from a context.

type ContextSetter

type ContextSetter func(c context.Context, value interface{}) context.Context

ContextSetter adds the resolved (and converted) claims to a context.

type ErrorHandler

type ErrorHandler interface {
	// Handle handles an error.
	Handle(ctx context.Context, err error)
}

ErrorHandler handles an error.

type MultiTokenExtractor added in v0.3.0

type MultiTokenExtractor []TokenExtractor

func (MultiTokenExtractor) ExtractToken added in v0.3.0

func (e MultiTokenExtractor) ExtractToken(req *http.Request) (string, error)

type Oauth2TokenExtractor added in v0.3.0

type Oauth2TokenExtractor struct{}

func (Oauth2TokenExtractor) ExtractToken added in v0.3.0

func (Oauth2TokenExtractor) ExtractToken(r *http.Request) (string, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func ErrorHandlerOption

func ErrorHandlerOption(errorHandler ErrorHandler) Option

func TokenExtractorOption added in v0.3.0

func TokenExtractorOption(extractor TokenExtractor) Option

func TokenStoreOption

func TokenStoreOption(tokenStore TokenStore) Option

type ScopedClaims

type ScopedClaims struct {
	jwt.Claims
	Scope string `json:"scope,omitempty"`
	// Drone fields
	Type TokenType `json:"type,omitempty"`
	Text string    `json:"text,omitempty"`
}

ScopedClaims struct to store the scoped claim related things

type TokenExtractor added in v0.3.0

type TokenExtractor interface {
	ExtractToken(*http.Request) (string, error)
}

TokenExtractor is an interface for extracting a token from an HTTP request. The ExtractToken method should return a token string or an error. If no token is present, you must return ErrNoTokenInRequest.

type TokenStore

type TokenStore interface {
	Exists(userID, tokenID string) (bool, error)
}

type TokenType

type TokenType string

TokenType represents one of the possible token Types

Jump to

Keyboard shortcuts

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