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

        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

              type MultiTokenExtractor []TokenExtractor

              func (MultiTokenExtractor) ExtractToken

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

              type Oauth2TokenExtractor

              type Oauth2TokenExtractor struct{}

              func (Oauth2TokenExtractor) ExtractToken

              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

              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

                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