authsvc

package
v0.0.0-...-48cc618 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicatedUserName = errors.New("duplicated username")
	ErrUserNotFound       = errors.New("user not found")
)
View Source
var (
	ErrAuthenticationFailed = errors.New("authentication failed")
)
View Source
var (
	ErrInvalidRequest = errors.New("invalid request")
)

Functions

func MakeHandler

func MakeHandler(svc AuthService) http.Handler

func NscAddOperator

func NscAddOperator(name string, options ...string) error

func NscAddUser

func NscAddUser(name string, options ...string) error

Types

type AuthService

type AuthService interface {
	AddUser(ctx context.Context, userName, password string) (User, error)
	GetUser(ctx context.Context, userName string) (User, error)
	AddForbiddenDevice(ctx context.Context, userId string, deviceId int) error
	Login(ctx context.Context, userName, password string) (User, error)
}

func NewAuthService

func NewAuthService(r Repository) AuthService

type InMemoryRepository

type InMemoryRepository map[string]User

type Repository

type Repository interface {
	AddUser(userName, password string) (User, error)
	GetUser(userName string) (User, error)
	DeleteUser(userName string) error
	AddForbiddenDevice(userId string, deviceId int) error
	FindUser(userName, password string) (User, error)
}

func NewRepository

func NewRepository() Repository

type User

type User struct {
	UserName         string `json:"username"`
	Password         string `json:"-"`
	ForbiddenDevices []int  `json:"forbidden_devices"`
}

Jump to

Keyboard shortcuts

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