auth

package
v0.0.0-...-2731c89 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("not found")
	ErrAlreadyExist = errors.New("already exist")
)
View Source
var (
	ErrUsernameInvalidCharacters = errors.New("username contains invalid character")
	ErrUsernameTooShort          = errors.New("username is too short")
	ErrUsernameTooLong           = errors.New("username is too long")
	ErrPasswordInvalidCharacters = errors.New("password contains invalid character")
	ErrPasswordTooShort          = errors.New("password is too short")
	ErrPasswordTooLong           = errors.New("password is too long")
)

Functions

func ValidatePassword

func ValidatePassword(password string) error

func ValidateUsername

func ValidateUsername(username string) error

Types

type Account

type Account struct {
	Id uint
	Credentials
}

type Authenticator

type Authenticator interface {
	IssueToken(userId uint) (string, error)
	UserIdByToken(token string) (uint, error)
}

type Claims

type Claims struct {
	Id uint
	jwt.StandardClaims
}

type Credentials

type Credentials struct {
	Username string
	Password string
}

type JwtHandler

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

func NewJwtHandler

func NewJwtHandler(privateBytes, publicBytes []byte, keyExpiration time.Duration) (*JwtHandler, error)

func (JwtHandler) IssueToken

func (j JwtHandler) IssueToken(userId uint) (string, error)

func (JwtHandler) UserIdByToken

func (j JwtHandler) UserIdByToken(tokenString string) (uint, error)

type UserStorage

type UserStorage interface {
	CreateAccount(cred Credentials) (Account, error)
	GetAccountById(id uint) (Account, error)
	GetAccountByUsername(username string) (Account, error)
}

Jump to

Keyboard shortcuts

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