auth

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	AuthTokensDef []*TokenDef
	AuthTokens    map[string]string
}

Config contains the authorization token configuration.

type HandlerWrapper

type HandlerWrapper struct {
	common.HTTPHandler
	// contains filtered or unexported fields
}

HandlerWrapper wraps an existing HTTP handler and performs bearer token authorization. If authorized then the wrapped handler is invoked.

func NewHandlerWrapper

func NewHandlerWrapper(handler common.HTTPHandler, tm tokenManager) *HandlerWrapper

NewHandlerWrapper returns a handler that first performs bearer token authorization and, if authorized, invokes the wrapped handler.

func (*HandlerWrapper) Handler

Handler returns the 'wrapper' handler.

type TokenDef

type TokenDef struct {
	EndpointExpression string
	ReadTokens         []string
	WriteTokens        []string
}

TokenDef contains authorization bearer token definitions.

type TokenManager

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

TokenManager manages the authorization tokens for both the client and server.

func NewTokenManager

func NewTokenManager(cfg Config) (*TokenManager, error)

NewTokenManager returns a token mapper that performs bearer token authorization.

func (*TokenManager) IsAuthRequired

func (m *TokenManager) IsAuthRequired(endpoint, method string) (bool, error)

IsAuthRequired return true if authorization is required for the given endpoint/method.

func (*TokenManager) RequiredAuthTokens

func (m *TokenManager) RequiredAuthTokens(endpoint, method string) ([]string, error)

RequiredAuthTokens returns the authorization tokens required for the given endpoint and method.

type TokenVerifier

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

TokenVerifier authorizes requests with bearer tokens.

func NewTokenVerifier

func NewTokenVerifier(tm tokenManager, endpoint, method string) *TokenVerifier

NewTokenVerifier returns a verifier that performs bearer token authorization.

func (*TokenVerifier) Verify

func (h *TokenVerifier) Verify(req *http.Request) bool

Verify verifies that the request has the required bearer token. If not, false is returned.

Directories

Path Synopsis
mocks
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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