Documentation ¶
Index ¶
- Constants
- func NewMongoClient(cfg *MongoConfig) *mongo.Client
- func NewTokenStore(client *mongo.Client, db string, collection string) (store oauth2.TokenStore)
- type MgoAuth
- func (au *MgoAuth) Contains(scope string) bool
- func (au *MgoAuth) GetClientID() string
- func (au *MgoAuth) GetScope() string
- func (au *MgoAuth) GetUserID() string
- func (au *MgoAuth) SetClientID(id string)
- func (au *MgoAuth) SetScope(scope string)
- func (au *MgoAuth) SetUserID(id string)
- func (au *MgoAuth) UpdateAuthID()
- type MgoAuthStore
- type MgoTokenStore
- func (ts *MgoTokenStore) Create(info oauth2.TokenInfo) (err error)
- func (ts *MgoTokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) GetByAccount(userID string, clientID string) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) GetByBson(m bson.M) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) GetByCode(code string) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) GetByField(field string, value string) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) GetByRefresh(refresh string) (ti oauth2.TokenInfo, err error)
- func (ts *MgoTokenStore) H(name string, handler func(c *mongo.Collection))
- func (ts *MgoTokenStore) RemoveByAccess(access string) (err error)
- func (ts *MgoTokenStore) RemoveByAccount(userID string, clientID string) (err error)
- func (ts *MgoTokenStore) RemoveByCode(code string) (err error)
- func (ts *MgoTokenStore) RemoveByRefresh(refresh string) (err error)
- type MgoUserCfg
- type MgoUserMobile
- type MgoUserStore
- func (us *MgoUserStore) Find(id interface{}) (u o2x.User, err error)
- func (us *MgoUserStore) FindMobile(mobile string) (u o2x.User, err error)
- func (us *MgoUserStore) Remove(id interface{}) (err error)
- func (us *MgoUserStore) Save(u o2x.User) (err error)
- func (us *MgoUserStore) UpdatePwd(id interface{}, password string) (err error)
- func (us *MgoUserStore) UpdateScope(id interface{}, clientId, scope string) (err error)
- type MongoClientStore
- type MongoConfig
- type Oauth2Client
- type TokenData
- func (t *TokenData) GetAccess() string
- func (t *TokenData) GetAccessCreateAt() time.Time
- func (t *TokenData) GetAccessExpiresIn() time.Duration
- func (t *TokenData) GetClientID() string
- func (t *TokenData) GetCode() string
- func (t *TokenData) GetCodeCreateAt() time.Time
- func (t *TokenData) GetCodeExpiresIn() time.Duration
- func (t *TokenData) GetRedirectURI() string
- func (t *TokenData) GetRefresh() string
- func (t *TokenData) GetRefreshCreateAt() time.Time
- func (t *TokenData) GetRefreshExpiresIn() time.Duration
- func (t *TokenData) GetScope() string
- func (t *TokenData) GetUserID() string
- func (t *TokenData) New() oauth2.TokenInfo
- func (t *TokenData) SetAccess(access string)
- func (t *TokenData) SetAccessCreateAt(createAt time.Time)
- func (t *TokenData) SetAccessExpiresIn(exp time.Duration)
- func (t *TokenData) SetClientID(clientID string)
- func (t *TokenData) SetCode(code string)
- func (t *TokenData) SetCodeCreateAt(createAt time.Time)
- func (t *TokenData) SetCodeExpiresIn(exp time.Duration)
- func (t *TokenData) SetRedirectURI(redirectURI string)
- func (t *TokenData) SetRefresh(refresh string)
- func (t *TokenData) SetRefreshCreateAt(createAt time.Time)
- func (t *TokenData) SetRefreshExpiresIn(exp time.Duration)
- func (t *TokenData) SetScope(scope string)
- func (t *TokenData) SetUserID(userID string)
Constants ¶
const ( DefaultOauth2AuthDb = "oauth2" DefaultOauth2AuthCollection = "auth" )
const ( DefaultOauth2ClientDb = "oauth2" DefaultOauth2ClientCollection = "client" )
Variables ¶
This section is empty.
Functions ¶
func NewMongoClient ¶
func NewMongoClient(cfg *MongoConfig) *mongo.Client
NewMongoClient new mongo client
Types ¶
type MgoAuth ¶
type MgoAuth struct { AuthID string `bson:"_id" json:"-"` ClientID string `bson:"-" json:"client_id"` UserID string `bson:"-" json:"user_id"` Scope string `bson:"scope" json:"scope"` }
AuthID = ClientId + "__" + UserID
func (*MgoAuth) GetClientID ¶
func (*MgoAuth) SetClientID ¶
func (*MgoAuth) UpdateAuthID ¶
func (au *MgoAuth) UpdateAuthID()
type MgoAuthStore ¶
type MgoAuthStore struct {
// contains filtered or unexported fields
}
func NewAuthStore ¶
func NewAuthStore(client *mongo.Client, db string, collection string) (store *MgoAuthStore)
func (*MgoAuthStore) Exist ¶
func (s *MgoAuthStore) Exist(auth o2x.Auth) bool
whether the auth already exists
type MgoTokenStore ¶
type MgoTokenStore struct {
// contains filtered or unexported fields
}
MgoTokenStore MongoDB storage for OAuth 2.0
func (*MgoTokenStore) Create ¶
func (ts *MgoTokenStore) Create(info oauth2.TokenInfo) (err error)
Create create and store the new token information
func (*MgoTokenStore) GetByAccess ¶
func (ts *MgoTokenStore) GetByAccess(access string) (ti oauth2.TokenInfo, err error)
GetByAccess use the access token for token information data
func (*MgoTokenStore) GetByAccount ¶
func (ts *MgoTokenStore) GetByAccount(userID string, clientID string) (ti oauth2.TokenInfo, err error)
GetByAccount get the exists token info by userID and clientID
func (*MgoTokenStore) GetByBson ¶
func (ts *MgoTokenStore) GetByBson(m bson.M) (ti oauth2.TokenInfo, err error)
GetByField use field value for token information data
func (*MgoTokenStore) GetByCode ¶
func (ts *MgoTokenStore) GetByCode(code string) (ti oauth2.TokenInfo, err error)
GetByCode use the authorization code for token information data
func (*MgoTokenStore) GetByField ¶
func (ts *MgoTokenStore) GetByField(field string, value string) (ti oauth2.TokenInfo, err error)
GetByField use field value for token information data
func (*MgoTokenStore) GetByRefresh ¶
func (ts *MgoTokenStore) GetByRefresh(refresh string) (ti oauth2.TokenInfo, err error)
GetByRefresh use the refresh token for token information data
func (*MgoTokenStore) H ¶
func (ts *MgoTokenStore) H(name string, handler func(c *mongo.Collection))
func (*MgoTokenStore) RemoveByAccess ¶
func (ts *MgoTokenStore) RemoveByAccess(access string) (err error)
RemoveByAccess use the access token to delete the token information
func (*MgoTokenStore) RemoveByAccount ¶
func (ts *MgoTokenStore) RemoveByAccount(userID string, clientID string) (err error)
RemoveByAccount remove exists token info by userID and clientID
func (*MgoTokenStore) RemoveByCode ¶
func (ts *MgoTokenStore) RemoveByCode(code string) (err error)
RemoveByCode use the authorization code to delete the token information
func (*MgoTokenStore) RemoveByRefresh ¶
func (ts *MgoTokenStore) RemoveByRefresh(refresh string) (err error)
RemoveByRefresh use the refresh token to delete the token information
type MgoUserCfg ¶
type MgoUserCfg struct {
// contains filtered or unexported fields
}
func DefaultMgoUserCfg ¶
func DefaultMgoUserCfg() *MgoUserCfg
type MgoUserMobile ¶
type MgoUserMobile struct { Id string `bson:"_id" json:"_id"` Mobile string `bson:"mobile" json:"mobile"` }
used to control the unique mobile for one user if exists
type MgoUserStore ¶
type MgoUserStore struct {
// contains filtered or unexported fields
}
func NewUserStore ¶
func NewUserStore(client *mongo.Client, db, collection string, userCfg *MgoUserCfg) (us *MgoUserStore)
func (*MgoUserStore) FindMobile ¶
func (us *MgoUserStore) FindMobile(mobile string) (u o2x.User, err error)
func (*MgoUserStore) Remove ¶
func (us *MgoUserStore) Remove(id interface{}) (err error)
func (*MgoUserStore) UpdatePwd ¶
func (us *MgoUserStore) UpdatePwd(id interface{}, password string) (err error)
func (*MgoUserStore) UpdateScope ¶
func (us *MgoUserStore) UpdateScope(id interface{}, clientId, scope string) (err error)
type MongoClientStore ¶
type MongoClientStore struct {
// contains filtered or unexported fields
}
Mongo client store
func NewClientStore ¶
func NewClientStore(client *mongo.Client, db string, collection string) (clientStore *MongoClientStore)
func (*MongoClientStore) GetByID ¶
func (cs *MongoClientStore) GetByID(id string) (cli oauth2.ClientInfo, err error)
GetByID according to the ID for the client information
func (*MongoClientStore) Set ¶
func (cs *MongoClientStore) Set(id string, cli oauth2.ClientInfo) (err error)
Add a client info
type MongoConfig ¶
type MongoConfig struct { Hosts []string Database string Username string Password string PoolLimit uint64 }
MongoConfig mongodb configuration parameters
type Oauth2Client ¶
type Oauth2Client struct { ID string `bson:"_id" json:"id"` Secret string `bson:"secret" json:"secret"` Domain string `bson:"domain" json:"domain"` Scopes []string `bson:"scopes" json:"scopes"` GrantTypes []oauth2.GrantType `bson:"grant_types" json:"grant_types"` UserID string `bson:"user_id,omitempty" json:"user_id,omitempty"` }
func (*Oauth2Client) GetDomain ¶
func (c *Oauth2Client) GetDomain() string
func (*Oauth2Client) GetGrantTypes ¶
func (c *Oauth2Client) GetGrantTypes() []oauth2.GrantType
func (*Oauth2Client) GetID ¶
func (c *Oauth2Client) GetID() string
func (*Oauth2Client) GetScopes ¶
func (c *Oauth2Client) GetScopes() []string
func (*Oauth2Client) GetSecret ¶
func (c *Oauth2Client) GetSecret() string
func (*Oauth2Client) GetUserID ¶
func (c *Oauth2Client) GetUserID() string
type TokenData ¶
type TokenData struct { Access string `bson:"_id" json:"Access"` ClientID string `bson:"ClientId" json:"ClientId"` UserID string `bson:"UserID" json:"UserID"` RedirectURI string `bson:"RedirectURI,omitempty" json:"RedirectURI,omitempty"` Scope string `bson:"Scope,omitempty" json:"Scope,omitempty"` Code string `bson:"Code,omitempty" json:"Code,omitempty"` CodeCreateAt time.Time `bson:"CodeCreateAt" json:"CodeCreateAt"` CodeExpiresIn time.Duration `bson:"CodeExpiresIn" json:"CodeExpiresIn"` AccessCreateAt time.Time `bson:"AccessCreateAt" json:"AccessCreateAt"` AccessExpiresIn time.Duration `bson:"AccessExpiresIn" json:"AccessExpiresIn"` Refresh string `bson:"Refresh,omitempty" json:"Refresh,omitempty"` RefreshCreateAt time.Time `bson:"RefreshCreateAt,omitempty" json:"RefreshCreateAt,omitempty"` RefreshExpiresIn time.Duration `bson:"RefreshExpiresIn,omitempty" json:"RefreshExpiresIn,omitempty"` ExpiredAt time.Time `bson:"ExpiredAt" json:"ExpiredAt"` }
func (*TokenData) GetAccessCreateAt ¶
GetAccessCreateAt create Time
func (*TokenData) GetAccessExpiresIn ¶
GetAccessExpiresIn the lifetime in seconds of the access token
func (*TokenData) GetCodeCreateAt ¶
GetCodeCreateAt create Time
func (*TokenData) GetCodeExpiresIn ¶
GetCodeExpiresIn the lifetime in seconds of the authorization code
func (*TokenData) GetRedirectURI ¶
GetRedirectURI redirect URI
func (*TokenData) GetRefreshCreateAt ¶
GetRefreshCreateAt create Time
func (*TokenData) GetRefreshExpiresIn ¶
GetRefreshExpiresIn the lifetime in seconds of the refresh token
func (*TokenData) New ¶
func (t *TokenData) New() oauth2.TokenInfo
New create to token model instance
func (*TokenData) SetAccessCreateAt ¶
SetAccessCreateAt create Time
func (*TokenData) SetAccessExpiresIn ¶
SetAccessExpiresIn the lifetime in seconds of the access token
func (*TokenData) SetClientID ¶
SetClientID the client id
func (*TokenData) SetCodeCreateAt ¶
SetCodeCreateAt create Time
func (*TokenData) SetCodeExpiresIn ¶
SetCodeExpiresIn the lifetime in seconds of the authorization code
func (*TokenData) SetRedirectURI ¶
SetRedirectURI redirect URI
func (*TokenData) SetRefresh ¶
SetRefresh refresh Token
func (*TokenData) SetRefreshCreateAt ¶
SetRefreshCreateAt create Time
func (*TokenData) SetRefreshExpiresIn ¶
SetRefreshExpiresIn the lifetime in seconds of the refresh token