apiauth

package
v0.0.0-...-fc67457 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConfig is returned when the config is invalid.
	ErrInvalidConfig = errors.New("invalid config")
)
View Source
var Module = fx.Module("auth",
	fx.Provide(
		func(in AuthIn) (AuthOut, error) {
			auth, err := New(
				WithConfig(in.Config),
			)

			return AuthOut{
				Auth: auth}, err
		},
	),
)

Functions

func WithConfig

func WithConfig(c Config) optionFunc

Types

type Auth

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

Auth is a struct that holds the auth middleware.

func New

func New(opts ...Option) (*Auth, error)

New creates a new Auth middleware.

func (*Auth) Protected

func (auth *Auth) Protected() bool

func (*Auth) Then

func (auth *Auth) Then(h http.HandlerFunc) http.Handler

type AuthIn

type AuthIn struct {
	fx.In
	Config Config
}

type AuthOut

type AuthOut struct {
	fx.Out
	Auth *Auth
}

type Basic

type Basic map[string]string

Basic is a map of usernames to passwords.

type Config

type Config struct {
	// Disable is a flag that if set to true, will disable all auth.  If this
	// is not set and no other auth is configured, then an error will be returned.
	Disable bool

	// Basic is a map of usernames to passwords.  If this is set, then basic auth
	// will be enabled.
	// If JWT is also set, then JWT will take precedence and basic auth will be ignored.
	Basic Basic

	// JWT holds the configuration for JWT based auth.
	JWT JWT
}

Config is a struct that holds the configuration for the Auth middleware.

type JWT

type JWT struct {
	// KeyProvider holds the configuration for the key provider.
	KeyProvider Provider

	// RequiredServiceCapabilities is a list of capabilities that are required
	// to be present to accept the token.  If any one of these capabilities are
	// present will allow the token to be accepted.
	RequiredServiceCapabilities []string
}

JWT is a struct that holds the configuration for JWT based auth.

type Option

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

Option is an interface that is used to apply options to the Auth struct.

type Provider

type Provider struct {
	// URL is the URL to get the public keys from.
	URL string

	// RefreshInterval is the interval to refresh the public keys.
	RefreshInterval time.Duration

	// HTTPClient is the configuration for the http client to use to get the public keys.
	HTTPClient arrangehttp.ClientConfig

	// DisableAutoAddMissingAlgorithm is a flag that if set to true, will disable
	// the automatic addition of missing algorithms to keys that are missing them.
	// If this is not set, then the default is to add missing algorithms to keys
	// that are missing the "alg" field.  Sometimes the public key provider does
	// not provide the "alg" field, and this function can be used to add it.
	DisableAutoAddMissingAlgorithm bool
}

Provider contains the configuration for accessing the public keys for JWT verification.

Jump to

Keyboard shortcuts

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