auth

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewErrUnauthorised

func NewErrUnauthorised(reason string) error

Types

type Authenticator

type Authenticator interface {
	// Authenticate takes a token and returns an authenticated Customer
	Authenticate(ctx context.Context, tokenStr string) (*Customer, *Token, error)

	// CanAccept takes a token and return true if it is supported. This function does not authenticate the token, only
	// whether the Authenticator can handle it.
	CanAccept(token string) bool
}

type Customer

type Customer struct {
	Id        string `json:"id"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Email     string `json:"email"`
	Brand     string `json:"brand"`
}

func (Customer) Validate

func (c Customer) Validate() error

Validate returns an error if the Customer is invalid

type ErrUnauthorised

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

func (ErrUnauthorised) Error

func (e ErrUnauthorised) Error() string

type Provider

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

Provider holds a slice of available authenticators

func NewProvider

func NewProvider(authenticators ...Authenticator) *Provider

NewProvider returns a new Provider containing the provided authenticators

func (Provider) Get

func (p Provider) Get(token string) (Authenticator, error)

Get takes a token and returns the first Authenticator that can accept the token.

type Token

type Token struct {
	Raw       string
	IssuedAt  *time.Time
	NotBefore *time.Time
	ExpiresAt *time.Time
}

func (*Token) Valid

func (t *Token) Valid() bool

Valid returns true if the Token has NotBefore set to nil or in the past and ExpiresAt set to nil or in the future.

Directories

Path Synopsis
jwt

Jump to

Keyboard shortcuts

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