o2m

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: 2

Documentation

Index

Constants

View Source
const (
	DefaultOauth2AuthDb         = "oauth2"
	DefaultOauth2AuthCollection = "auth"
)
View Source
const (
	DefaultOauth2ClientDb         = "oauth2"
	DefaultOauth2ClientCollection = "client"
)

Variables

This section is empty.

Functions

func NewMongoClient

func NewMongoClient(cfg *MongoConfig) *mongo.Client

NewMongoClient new mongo client

func NewTokenStore

func NewTokenStore(client *mongo.Client, db string,
	collection string) (store oauth2.TokenStore)

NewTokenStore create a token store instance based on mongodb

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) Contains

func (au *MgoAuth) Contains(scope string) bool

func (*MgoAuth) GetClientID

func (au *MgoAuth) GetClientID() string

func (*MgoAuth) GetScope

func (au *MgoAuth) GetScope() string

func (*MgoAuth) GetUserID

func (au *MgoAuth) GetUserID() string

func (*MgoAuth) SetClientID

func (au *MgoAuth) SetClientID(id string)

func (*MgoAuth) SetScope

func (au *MgoAuth) SetScope(scope string)

func (*MgoAuth) SetUserID

func (au *MgoAuth) SetUserID(id string)

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

func (*MgoAuthStore) Find

func (s *MgoAuthStore) Find(clientId string, userID string) (auth o2x.Auth, err error)

find auth by clientID and userID

func (*MgoAuthStore) Save

func (s *MgoAuthStore) Save(auth o2x.Auth) error

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) Find

func (us *MgoUserStore) Find(id interface{}) (u o2x.User, err error)

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) Save

func (us *MgoUserStore) Save(u o2x.User) (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 Copy

func Copy(info oauth2.TokenInfo) (token *TokenData)

func (*TokenData) GetAccess

func (t *TokenData) GetAccess() string

GetAccess access Token

func (*TokenData) GetAccessCreateAt

func (t *TokenData) GetAccessCreateAt() time.Time

GetAccessCreateAt create Time

func (*TokenData) GetAccessExpiresIn

func (t *TokenData) GetAccessExpiresIn() time.Duration

GetAccessExpiresIn the lifetime in seconds of the access token

func (*TokenData) GetClientID

func (t *TokenData) GetClientID() string

GetClientID the client id

func (*TokenData) GetCode

func (t *TokenData) GetCode() string

GetCode authorization code

func (*TokenData) GetCodeCreateAt

func (t *TokenData) GetCodeCreateAt() time.Time

GetCodeCreateAt create Time

func (*TokenData) GetCodeExpiresIn

func (t *TokenData) GetCodeExpiresIn() time.Duration

GetCodeExpiresIn the lifetime in seconds of the authorization code

func (*TokenData) GetRedirectURI

func (t *TokenData) GetRedirectURI() string

GetRedirectURI redirect URI

func (*TokenData) GetRefresh

func (t *TokenData) GetRefresh() string

GetRefresh refresh Token

func (*TokenData) GetRefreshCreateAt

func (t *TokenData) GetRefreshCreateAt() time.Time

GetRefreshCreateAt create Time

func (*TokenData) GetRefreshExpiresIn

func (t *TokenData) GetRefreshExpiresIn() time.Duration

GetRefreshExpiresIn the lifetime in seconds of the refresh token

func (*TokenData) GetScope

func (t *TokenData) GetScope() string

GetScope get scope of authorization

func (*TokenData) GetUserID

func (t *TokenData) GetUserID() string

GetUserID the user id

func (*TokenData) New

func (t *TokenData) New() oauth2.TokenInfo

New create to token model instance

func (*TokenData) SetAccess

func (t *TokenData) SetAccess(access string)

SetAccess access Token

func (*TokenData) SetAccessCreateAt

func (t *TokenData) SetAccessCreateAt(createAt time.Time)

SetAccessCreateAt create Time

func (*TokenData) SetAccessExpiresIn

func (t *TokenData) SetAccessExpiresIn(exp time.Duration)

SetAccessExpiresIn the lifetime in seconds of the access token

func (*TokenData) SetClientID

func (t *TokenData) SetClientID(clientID string)

SetClientID the client id

func (*TokenData) SetCode

func (t *TokenData) SetCode(code string)

SetCode authorization code

func (*TokenData) SetCodeCreateAt

func (t *TokenData) SetCodeCreateAt(createAt time.Time)

SetCodeCreateAt create Time

func (*TokenData) SetCodeExpiresIn

func (t *TokenData) SetCodeExpiresIn(exp time.Duration)

SetCodeExpiresIn the lifetime in seconds of the authorization code

func (*TokenData) SetRedirectURI

func (t *TokenData) SetRedirectURI(redirectURI string)

SetRedirectURI redirect URI

func (*TokenData) SetRefresh

func (t *TokenData) SetRefresh(refresh string)

SetRefresh refresh Token

func (*TokenData) SetRefreshCreateAt

func (t *TokenData) SetRefreshCreateAt(createAt time.Time)

SetRefreshCreateAt create Time

func (*TokenData) SetRefreshExpiresIn

func (t *TokenData) SetRefreshExpiresIn(exp time.Duration)

SetRefreshExpiresIn the lifetime in seconds of the refresh token

func (*TokenData) SetScope

func (t *TokenData) SetScope(scope string)

SetScope get scope of authorization

func (*TokenData) SetUserID

func (t *TokenData) SetUserID(userID string)

SetUserID the user id

Jump to

Keyboard shortcuts

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