o2x

package
v1.1.3-0...-e5dd412 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrCodeInternalError     = 100
	ErrCodeInvalidCredential = 101
	ErrCodeInvalidCaptcha    = 102
	ErrCodeValueRequired     = 200
	ErrCodeNotFound          = 201
	ErrCodeDuplicated        = 202
)
View Source
const (
	CaptchaCredentials oauth2.GrantType = "captcha"
)

Variables

View Source
var (
	ErrInternalError     = NewOauthError(http.StatusInternalServerError, ErrCodeInternalError, "internal error")
	ErrInvalidCredential = NewOauthError(http.StatusUnauthorized, ErrCodeInvalidCredential, "invalid credential")
	ErrInvalidCaptcha    = NewOauthError(http.StatusUnauthorized, ErrCodeInvalidCaptcha, "invalid captcha")
	ErrValueRequired     = NewOauthError(http.StatusBadRequest, ErrCodeValueRequired, "value required")
	ErrNotFound          = NewOauthError(http.StatusNotFound, ErrCodeNotFound, "not found")
	ErrDuplicated        = NewOauthError(http.StatusConflict, ErrCodeDuplicated, "duplicated")
)
View Source
var (
	UserType          = reflect.TypeOf(new(User)).Elem()
	SimpleUserPtrType = reflect.TypeOf(&SimpleUser{})
)

Functions

func IsUserType

func IsUserType(t reflect.Type) bool

func ScopeArrContains

func ScopeArrContains(scopes []string, str string) bool

func ScopeContains

func ScopeContains(scope string, test string) bool

func ScopeIn

func ScopeIn(scopes []string, test string) bool

func ScopesIn

func ScopesIn(scopes []string, test []string) bool

func UserIdString

func UserIdString(uid interface{}) (id string, err error)

Types

type Auth

type Auth interface {
	GetClientID() string
	SetClientID(id string)

	GetUserID() string
	SetUserID(id string)

	GetScope() string
	SetScope(scope string)

	// whether the Scope of current auth contains the given Scope
	Contains(scope string) bool
}

type AuthModel

type AuthModel struct {
	ClientID string
	UserID   string
	Scope    string
}

--------------------------------------------------

func (*AuthModel) Contains

func (a *AuthModel) Contains(scope string) bool

func (*AuthModel) GetClientID

func (a *AuthModel) GetClientID() string

func (*AuthModel) GetScope

func (a *AuthModel) GetScope() string

func (*AuthModel) GetUserID

func (a *AuthModel) GetUserID() string

func (*AuthModel) SetClientID

func (a *AuthModel) SetClientID(id string)

func (*AuthModel) SetScope

func (a *AuthModel) SetScope(scope string)

func (*AuthModel) SetUserID

func (a *AuthModel) SetUserID(id string)

type AuthStore

type AuthStore interface {
	// save auth
	Save(auth Auth) error

	// find auth by ClientId and UserID
	Find(clientId string, userID string) (auth Auth, err error)

	// whether the auth already exists
	Exist(auth Auth) bool
}

type CaptchaStore

type CaptchaStore interface {
	Save(mobile, captcha string) (err error)
	Remove(mobile string) (err error)
	Valid(mobile, captcha string) (valid bool, err error)
}

type CodeError

type CodeError interface {
	error
	Code() int
	Status() int
}

type Hexer

type Hexer interface {
	Hex() string
}

type MemoryAuthStore

type MemoryAuthStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewAuthStore

func NewAuthStore() *MemoryAuthStore

func (*MemoryAuthStore) Exist

func (as *MemoryAuthStore) Exist(auth Auth) bool

func (*MemoryAuthStore) Find

func (as *MemoryAuthStore) Find(clientId string, userID string) (auth Auth, err error)

func (*MemoryAuthStore) Save

func (as *MemoryAuthStore) Save(auth Auth) error

type MemoryCaptchaStore

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

func NewMemoryCaptchaStore

func NewMemoryCaptchaStore(expireDuration time.Duration) (cs *MemoryCaptchaStore, err error)

func (*MemoryCaptchaStore) Remove

func (cs *MemoryCaptchaStore) Remove(mobile string) (err error)

func (*MemoryCaptchaStore) Save

func (cs *MemoryCaptchaStore) Save(mobile, captcha string) (err error)

func (*MemoryCaptchaStore) Valid

func (cs *MemoryCaptchaStore) Valid(mobile, captcha string) (valid bool, err error)

type MemoryUserStore

type MemoryUserStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*MemoryUserStore) Find

func (cs *MemoryUserStore) Find(id interface{}) (u User, err error)

func (*MemoryUserStore) FindMobile

func (cs *MemoryUserStore) FindMobile(mobile string) (u User, err error)

func (*MemoryUserStore) Remove

func (cs *MemoryUserStore) Remove(id interface{}) (err error)

func (*MemoryUserStore) Save

func (cs *MemoryUserStore) Save(u User) (err error)

func (*MemoryUserStore) UpdatePwd

func (cs *MemoryUserStore) UpdatePwd(id interface{}, password string) (err error)

func (*MemoryUserStore) UpdateScope

func (cs *MemoryUserStore) UpdateScope(id interface{}, clientId, scope string) (err error)

type O2ClientInfo

type O2ClientInfo interface {
	oauth2.ClientInfo
	GetScopes() []string
	GetGrantTypes() []oauth2.GrantType
}

type O2ClientStore

type O2ClientStore interface {
	oauth2.ClientStore
	Set(id string, cli oauth2.ClientInfo) (err error)
}

type O2TokenStore

type O2TokenStore interface {
	oauth2.TokenStore

	RemoveByAccount(userID string, clientID string) (err error)
	GetByAccount(userID string, clientID string) (ti oauth2.TokenInfo, err error)
}

type OauthError

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

func NewOauthError

func NewOauthError(status, code int, err string) *OauthError

func (*OauthError) Code

func (e *OauthError) Code() int

func (*OauthError) Error

func (e *OauthError) Error() string

func (*OauthError) Status

func (e *OauthError) Status() int

type SimpleUser

type SimpleUser struct {
	UserID   interface{}       `bson:"_id" json:"user_id"`
	Mobile   string            `bson:"mobile" json:"mobile"`
	Password []byte            `bson:"password" json:"password"`
	Salt     []byte            `bson:"salt" json:"salt"`
	Scopes   map[string]string `bson:"scopes" json:"scopes,omitempty"`
}

-------------------------------

func (*SimpleUser) GetID

func (u *SimpleUser) GetID() string

func (*SimpleUser) GetMobile

func (u *SimpleUser) GetMobile() string

func (*SimpleUser) GetPassword

func (u *SimpleUser) GetPassword() []byte

func (*SimpleUser) GetSalt

func (u *SimpleUser) GetSalt() []byte

func (*SimpleUser) GetScopes

func (u *SimpleUser) GetScopes() map[string]string

func (*SimpleUser) GetUserID

func (u *SimpleUser) GetUserID() interface{}

func (*SimpleUser) Match

func (u *SimpleUser) Match(password string) bool

func (*SimpleUser) SetRawPassword

func (u *SimpleUser) SetRawPassword(password string)

func (*SimpleUser) SetUserID

func (u *SimpleUser) SetUserID(userID interface{})

type User

type User interface {
	GetID() string
	GetUserID() interface{}
	GetMobile() string
	GetPassword() []byte
	GetSalt() []byte
	GetScopes() map[string]string
	SetRawPassword(password string)
	Match(password string) bool
}

func NewUser

func NewUser(t reflect.Type) User

type UserStore

type UserStore interface {
	Save(u User) (err error)
	Remove(id interface{}) (err error)
	UpdatePwd(id interface{}, password string) (err error)
	UpdateScope(id interface{}, clientId, scope string) (err error)
	Find(id interface{}) (u User, err error)
	FindMobile(mobile string) (u User, err error)
}

func NewUserStore

func NewUserStore() UserStore

-------------------------------

type ValidResponse

type ValidResponse struct {
	ClientID string `json:"client_id,omitempty"`
	UserID   string `json:"user_id,omitempty"`
	Scope    string `json:"scope,omitempty"`
}

Jump to

Keyboard shortcuts

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