authenticator

package
v0.0.0-...-d386c04 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderAuthnCredentials = "authorization"
	HeaderAuthnEngine      = "x-authorization-engine"
	HeaderAuthnWorkspace   = "x-authorization-workspace"
)
View Source
var (
	ErrMalformedCredentials  = errors.New("AUTHENTICATOR.MALFORMED_CREDENTIALS")
	ErrMalformedScheme       = errors.New("AUTHENTICATOR.MALFORMED_SCHEME")
	ErrMalformedToken        = errors.New("AUTHENTICATOR.MALFORMED_TOKEN")
	ErrMalformedTokenPayload = errors.New("AUTHENTICATOR.MALFORMED_TOKEN_PAYLOAD")
	ErrInvalidCredentials    = errors.New("AUTHENTICATOR.INVALID_CREDENTIALS")
)
View Source
var EngineAsk = "ask"
View Source
var EngineExternal = "external"
View Source
var (
	SchemeBasic = "basic"
)

Functions

func ParseBasicCredentials

func ParseBasicCredentials(credentials string) (string, string, error)

Types

type Account

type Account struct {
	Sub      string            `json:"sub" yaml:"sub"`
	Name     string            `json:"name" yaml:"name"`
	Metadata map[string]string `json:"metadata" yaml:"metadata"`
}

Account is followed the document of https://www.iana.org/assignments/jwt/jwt.xhtml#claims

func (*Account) Validate

func (acc *Account) Validate() error

type Ask

type Ask struct {
	AccessKey string `json:"access_key" yaml:"access_key" mapstructure:"access_key"`
	SecretKey string `json:"secret_key" yaml:"secret_key" mapstructure:"secret_key"`
}

func (*Ask) Validate

func (conf *Ask) Validate() error

type Authenticator

type Authenticator interface {
	Engines() []string
	Register(engine string, verifier Verifier) error
	Authenticate(engine string, ctx context.Context, request *Request) (*Account, error)
}

func New

type Config

type Config struct {
	Engine   string    `json:"engine" yaml:"engine" mapstructure:"engine"`
	Ask      *Ask      `json:"ask" yaml:"ask" mapstructure:"ask"`
	External *External `json:"external" yaml:"external" mapstructure:"external"`
}

func (*Config) Validate

func (conf *Config) Validate() error

type External

type External struct {
	Uri     string          `json:"uri" yaml:"uri" mapstructure:"uri"`
	Headers []string        `json:"headers" yaml:"headers" mapstructure:"headers"`
	Mapper  *ExternalMapper `json:"mapper" yaml:"mapper" mapstructure:"mapper"`
}

func (*External) Validate

func (conf *External) Validate() error

type ExternalMapper

type ExternalMapper struct {
	Uri string `json:"uri" yaml:"uri" mapstructure:"uri"`
}

func (*ExternalMapper) Validate

func (conf *ExternalMapper) Validate() error

type Request

type Request struct {
	Credentials string
	Metadata    map[string]string
}

type Verifier

type Verifier interface {
	Verify(ctx context.Context, request *Request) (*Account, error)
}

func NewAsk

func NewAsk(conf *Ask) (Verifier, error)

func NewExternal

func NewExternal(conf *External, logger logging.Logger, send sender.Send, cb circuitbreaker.CircuitBreaker) (Verifier, error)

Jump to

Keyboard shortcuts

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