hello

package module
Version: v0.0.0-...-5221745 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2021 License: MIT Imports: 12 Imported by: 0

README

hello

tokens

payload.signature

format: payload and signature delimited by a period.

payload: any byte array, base64 url encoded, padding trimmed.

signature: hash of payload + secret, base64 url encoded, padding trimmed.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password, salt string) string

func NewCreateUserHandler

func NewCreateUserHandler(u UserStorage, tm UserTokenManager) http.HandlerFunc

NewCreateUserHandler creates a new user. the required token is generally a system token, or an admin token.

func NewLoginHandler

func NewLoginHandler(u UserStorage, tm UserTokenManager) http.HandlerFunc

func NewRefreshHandler

func NewRefreshHandler(tm UserTokenManager) http.HandlerFunc

NewRefreshHandler generates a new token, using an existing token.

func NewSalt

func NewSalt(size int) string

func NewToken

func NewToken(secret []byte, body []byte) string

func VerifyToken

func VerifyToken(secret []byte, token string) ([]byte, error)

Types

type Password

type Password struct {
	Hash    string
	Salt    string
	Expired bool
	Created time.Time
}

func NewPassword

func NewPassword(value string) Password

func (*Password) Is

func (p *Password) Is(value string) bool

type User

type User struct {
	ID        string
	Name      string
	Passwords []Password
	Created   time.Time
	Creator   string
}

func NewUser

func NewUser(name string, pass string) User

func (*User) HasPassword

func (u *User) HasPassword(password string, allowExpired bool) bool

func (*User) SetPassword

func (u *User) SetPassword(value string)

type UserStorage

type UserStorage interface {
	Put(u User) error
	Get(id string) (User, bool, error)
	GetByName(name string) (User, bool, error)
}

type UserToken

type UserToken struct {
	User
	Expires time.Time
}

func (*UserToken) Verify

func (ut *UserToken) Verify() error

type UserTokenManager

type UserTokenManager interface {
	NewToken(User) string
	VerifyToken(token string) (User, error)
}

func NewUserTokenManager

func NewUserTokenManager(secret []byte) UserTokenManager

Directories

Path Synopsis
internal
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL