auth

package
v0.0.0-...-1703965 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2016 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserIdInvalid           = errors.New("User id must be 5 - 32 letters,digits or _")
	ErrUserIdForbidden         = errors.New("User id is not allowed")
	ErrWrongUsernameOrPassword = errors.New("Username or password incorrect")
	ErrWrongRefreshToken       = errors.New("Refresh token incorrect")
)
View Source
var (
	ErrNotFound   = errors.New("No record found")
	ErrUserExists = errors.New("User Id exists")
)

Functions

func IsUserError

func IsUserError(err error) bool

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(newKey []byte) (newObj *Authenticator)

func (Authenticator) CreateUser

func (authenticator Authenticator) CreateUser(
	useridStr string, name string, password []byte, clientId string,
	otherFields map[UserFieldName]interface{}, userStorage UserDb_I) (*string, *string, error)

func (Authenticator) Login

func (authenticator Authenticator) Login(
	useridStr string, password []byte, clientId string,
	userStorage UserDb_I) (acToken *string, refToken *string,
	name *string, language *string, e error)

func (Authenticator) VerifyPrivilege

func (authenticator Authenticator) VerifyPrivilege(
	userInfo UserAuthInfo, levelToMeet PVL) (ok bool, err error)

-- No db access

type Language

type Language string
const (
	English            Language = "en"
	SimplifiedChinese  Language = "zh-Hans"
	TraditionalChinese Language = "zh-Hant"
)

type MockUserCredentials_I

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

Mock of UserCredentials_I interface

func NewMockUserCredentials_I

func NewMockUserCredentials_I(ctrl *gomock.Controller) *MockUserCredentials_I

func (*MockUserCredentials_I) EXPECT

func (_m *MockUserCredentials_I) EXPECT() *_MockUserCredentials_IRecorder

func (*MockUserCredentials_I) UserId

func (_m *MockUserCredentials_I) UserId() UserId

type MockUserDb_I

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

Mock of UserDb_I interface

func NewMockUserDb_I

func NewMockUserDb_I(ctrl *gomock.Controller) *MockUserDb_I

func (*MockUserDb_I) CreateUser

func (_m *MockUserDb_I) CreateUser(userid UserId, name string, hashedPassword []byte, priv PVL, otherFields map[UserFieldName]interface{}) error

func (*MockUserDb_I) EXPECT

func (_m *MockUserDb_I) EXPECT() *_MockUserDb_IRecorder

func (*MockUserDb_I) GetFields

func (_m *MockUserDb_I) GetFields(userid UserId, fields []UserFieldName) (map[UserFieldName]interface{}, error)

func (*MockUserDb_I) GetRefreshToken

func (_m *MockUserDb_I) GetRefreshToken(userid UserId, clientId string) (*string, error)

func (*MockUserDb_I) SetRefreshToken

func (_m *MockUserDb_I) SetRefreshToken(userid UserId, clientId string, refreshToken string) error

func (*MockUserDb_I) UpdateUser

func (_m *MockUserDb_I) UpdateUser(userid UserId, fields map[UserFieldName]interface{}) error

type PVL

type PVL int32
const (
	None PVL = iota //0
	God
	Admin
	PremiumUser
	RegularUser
)

type RefreshFieldName

type RefreshFieldName string
const (
	RefreshField_UserId     RefreshFieldName = "userid"
	RefreshField_ClientId   RefreshFieldName = "client_id"
	RefreshField_RefreshTok RefreshFieldName = "refresh_token"
)

type UserAuthInfo

type UserAuthInfo struct {
	UserId UserId
	// contains filtered or unexported fields
}

func NewUserAuthInfo

func NewUserAuthInfo(newUserIdStr string, newAccessToken string) (
	*UserAuthInfo, error)

type UserCredentials_I

type UserCredentials_I interface {
	UserId() UserId
	// contains filtered or unexported methods
}

type UserDb_I

type UserDb_I interface {
	GetFields(userid UserId, fields []UserFieldName) (map[UserFieldName]interface{}, error)

	UpdateUser(userid UserId, fields map[UserFieldName]interface{}) error

	CreateUser(userid UserId, name string, hashedPassword []byte, priv PVL, otherFields map[UserFieldName]interface{}) error

	GetRefreshToken(userid UserId, clientId string) (*string, error)

	SetRefreshToken(userid UserId, clientId string, refreshToken string) error
}

type UserFieldName

type UserFieldName string
const (
	UserField_Priv     UserFieldName = "priv"
	UserField_UserId   UserFieldName = "userid"
	UserField_Name     UserFieldName = "username"
	UserField_Password UserFieldName = "password"
	UserField_Language UserFieldName = "lang"
)

type UserIDPassword

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

func NewUserIDPassword

func NewUserIDPassword(newUserIdStr string, password []byte) (*UserIDPassword, error)

func (UserIDPassword) UserId

func (u UserIDPassword) UserId() UserId

type UserIDRefreshToken

type UserIDRefreshToken struct {
	RefreshToken string
	// contains filtered or unexported fields
}

func (UserIDRefreshToken) UserId

func (u UserIDRefreshToken) UserId() UserId

type UserId

type UserId struct {
	Id string `validate:"min=5,max=32,regexp=^[a-zA-Z_0-9]*$,user_notstopword"`
}

func NewUserid

func NewUserid(newId string) (*UserId, error)

Jump to

Keyboard shortcuts

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