basic

package
v0.32.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package basic implements a simple auth provider and backend that identifies a user via username & password combination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateBasicAuth added in v0.31.0

func ValidateBasicAuth(ctx context.Context) error

ValidateBasicAuth returns an access denied error for non-admins when basic auth is disabled in configs.

Types

type Config

type Config struct {
}

Config configures the basic auth provider

type HashedPassword added in v0.31.0

type HashedPassword interface {
	Hash() string
	// contains filtered or unexported methods
}

HashedPassword is an interface that can be used to store a password.

type Provider

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

Provider implements the auth.IdentityProvider interface.

func NewProvider

func NewProvider(ctx context.Context, store *Store) (*Provider, error)

NewProvider creates a new Provider with the associated config.

func (*Provider) ExtractIdentity

func (p *Provider) ExtractIdentity(route *auth.RouteInfo, w http.ResponseWriter, req *http.Request) (*auth.Identity, error)

ExtractIdentity implements the auth.IdentityProvider interface, providing identity based on the given username and password fields.

func (Provider) Info

Info implements the auth.Provider interface.

type Store

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

Store can create new user/pass links and validate a username and password. bcrypt is used for password storage & verification.

func NewStore

func NewStore(ctx context.Context, db *sql.DB) (*Store, error)

NewStore creates a new DB. Error is returned if the prepared statements fail to register.

func (*Store) CreateTx

func (b *Store) CreateTx(ctx context.Context, tx *sql.Tx, userID, username string, password HashedPassword) error

CreateTx should add a new entry for the username/password combination linking to userID. An error is returned if the username is not unique or the userID is invalid. Must have same user or admin role.

func (*Store) NewHashedPassword added in v0.31.0

func (b *Store) NewHashedPassword(ctx context.Context, password string) (HashedPassword, error)

NewHashedPassword will hash the given password and return a Password object.

func (*Store) UpdateTx added in v0.31.0

func (b *Store) UpdateTx(ctx context.Context, tx *sql.Tx, userID string, oldPass ValidatedPassword, newPass HashedPassword) error

UpdateTx updates a user's password. oldPass is required if the current context is not an admin.

func (*Store) Validate

func (b *Store) Validate(ctx context.Context, username, password string) (string, error)

Validate should return a userID if the username and password match.

func (*Store) ValidatePassword added in v0.31.0

func (b *Store) ValidatePassword(ctx context.Context, password string) (ValidatedPassword, error)

ValidatePassword will validate the password of the currently authenticated user.

type ValidatedPassword added in v0.31.0

type ValidatedPassword interface {
	UserID() string
	// contains filtered or unexported methods
}

ValidatedPassword represents a validated password for a UserID.

Jump to

Keyboard shortcuts

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