auth

package
v0.0.0-...-0da5870 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserAlreadyExists indicates the user already exists.
	ErrUserAlreadyExists = errors.New("User already exists")

	// ErrUserDoesNotExist indicates the given username does not exist.
	ErrUserDoesNotExist = errors.New("User does not exist")

	// ErrUsernameEmpty indicates the given username was empty.
	ErrUsernameEmpty = errors.New("Username cannot be empty")

	// ErrPasswordTooShort indicates the given password was too short.
	ErrPasswordTooShort = errors.New("Password must be at least 6 characters long")
)

Functions

func HashPassword

func HashPassword(password string) ([]byte, error)

HashPassword creates a secure hash of a password for storage.

func ValidatePassword

func ValidatePassword(hash []byte, password string) error

ValidatePassword checks the given plaintext password against the stored hash.

Types

type Auth

type Auth interface {
	// Login validates the given credentials and if successful, generates a token.
	Login(username, password string) (string, error)

	// AddUser adds a new user.
	AddUser(user *User) error

	// UpdateUser updates an existing user.
	UpdateUser(user *User) error

	// SetPassword sets a password for a user.
	SetPassword(username, password string) error

	// GetUser gets a User object.
	GetUser(username string) (*User, error)

	// DeleteUser deletes a User.
	DeleteUser(username string) error
}

Auth provides authentication.

func Resolve

func Resolve(path string, tm *TokenManager) (Auth, error)

Resolve the given connection string to a specific Auth implementation.

type TokenManager

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

TokenManager object.

func NewTokenManager

func NewTokenManager(key []byte, ttl time.Duration) *TokenManager

NewTokenManager returns a new TokenManager.

func (*TokenManager) Generate

func (t *TokenManager) Generate(username string) (string, error)

Generate a token for a username.

func (*TokenManager) Validate

func (t *TokenManager) Validate(token string) (string, error)

Validate and return the username for a token.

type User

type User struct {
	Username string `json:"username,omitempty"`
	Disabled bool   `json:"disabled,omitempty"`
	Admin    bool   `json:"admin,omitempty"`
}

User object.

type UserPassAuth

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

UserPassAuth implements basic user password authentication using a BoltDB backend.

func NewUserPassAuth

func NewUserPassAuth(address string, tm *TokenManager) (*UserPassAuth, error)

NewUserPassAuth creates a new UserPassAuth object.

func (*UserPassAuth) AddUser

func (a *UserPassAuth) AddUser(user *User) error

AddUser adds a new user.

func (*UserPassAuth) DeleteUser

func (a *UserPassAuth) DeleteUser(username string) error

DeleteUser deletes a User.

func (*UserPassAuth) GetUser

func (a *UserPassAuth) GetUser(username string) (*User, error)

GetUser gets a User object.

func (*UserPassAuth) Login

func (a *UserPassAuth) Login(username, password string) (string, error)

Login validates the given credentials and if successful, generates a token.

func (*UserPassAuth) SetPassword

func (a *UserPassAuth) SetPassword(username, password string) error

SetPassword sets a password for a user.

func (*UserPassAuth) UpdateUser

func (a *UserPassAuth) UpdateUser(user *User) error

UpdateUser updates an existing user.

Jump to

Keyboard shortcuts

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