auth

package
v0.0.0-...-98462bc Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = errors.New("unauthorized")
)

Functions

func SetAuthenticationDetails

func SetAuthenticationDetails(r *http.Request, u *User) *http.Request

SetAuthenticationDetails sets user details for this request

Types

type AuthRequest

type AuthRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
	// JWT
	Token    string
	AuthType AuthType `json:"-"`
}

type AuthResponse

type AuthResponse struct {
	Token string `json:"token"`
	User  User   `json:"-"`
}

type AuthType

type AuthType int
const (
	AuthTypeUnknown AuthType = iota
	AuthTypeBasic
	AuthTypeToken
)

type Authenticator

type Authenticator interface {
	// indicates whether authentication is enabled
	Enabled() bool
	Authenticate(req *AuthRequest) (*AuthResponse, error)
	GenerateToken(u User) (*AuthResponse, error)
}

type DefaultAuthenticator

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

func New

func New(opts *Opts) *DefaultAuthenticator

func (*DefaultAuthenticator) Authenticate

func (a *DefaultAuthenticator) Authenticate(req *AuthRequest) (*AuthResponse, error)

func (*DefaultAuthenticator) Enabled

func (a *DefaultAuthenticator) Enabled() bool

func (*DefaultAuthenticator) GenerateToken

func (a *DefaultAuthenticator) GenerateToken(u User) (*AuthResponse, error)

type Opts

type Opts struct {
	// Basic auth
	Username string
	Password string

	// Secret used to sign JWT tokens
	Secret []byte
}

type User

type User struct {
	Username string
}

func GetAccountFromCtx

func GetAccountFromCtx(ctx context.Context) *User

GetAccountFromCtx - get current authenticated account info from ctx

Jump to

Keyboard shortcuts

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