Documentation ¶
Index ¶
- Constants
- Variables
- type ClientController
- type ClientModel
- type CollectionController
- type Database
- type MongoClientController
- func (cc *MongoClientController) Batch(n, skip int64) ([]ClientModel, error)
- func (cc *MongoClientController) Count() (int64, error)
- func (cc *MongoClientController) Create(client ClientModel) (string, error)
- func (cc *MongoClientController) DeleteByID(id string) error
- func (cc *MongoClientController) FindByID(id string) (ClientModel, error)
- func (cc *MongoClientController) FindByName(name string) (ClientModel, error)
- type MongoDatabase
- type MongoState
- type MongoTokenController
- func (cc *MongoTokenController) CreateAccess(tk TokenModel) (string, error)
- func (cc *MongoTokenController) CreateAuth(tk TokenModel) (string, error)
- func (cc *MongoTokenController) CreateRefresh(tk TokenModel) (string, error)
- func (cc *MongoTokenController) DeleteAccessByID(id string) error
- func (cc *MongoTokenController) DeleteAuthByID(id string) error
- func (cc *MongoTokenController) DeleteRefreshByID(id string) error
- func (cc *MongoTokenController) FindAccessByID(id string) (TokenModel, error)
- func (cc *MongoTokenController) FindAuthByID(id string) (TokenModel, error)
- func (cc *MongoTokenController) FindRefreshByID(id string) (TokenModel, error)
- type MongoUserController
- func (cc *MongoUserController) Batch(n, skip int64) ([]UserModel, error)
- func (cc *MongoUserController) Count() (int64, error)
- func (cc *MongoUserController) Create(usr UserModel) (string, error)
- func (cc *MongoUserController) CreatePending(usr PendingUserModel) (string, error)
- func (cc *MongoUserController) DeletePendingByID(id string) error
- func (cc *MongoUserController) FindByEmail(email string) (UserModel, error)
- func (cc *MongoUserController) FindByID(id string) (UserModel, error)
- func (cc *MongoUserController) FindPendingByEmail(email string) (PendingUserModel, error)
- func (cc *MongoUserController) FindPendingByID(id string) (PendingUserModel, error)
- func (cc *MongoUserController) Update(usr UserModel) (int64, error)
- type PendingUserModel
- type TokenController
- type TokenModel
- type UserController
- type UserModel
Constants ¶
const OP_TIMEOUT = 300 * time.Millisecond
OP_TIMEOUT is the maximum allowed duration allotted to a single database operation.
Variables ¶
var ErrClosed = fmt.Errorf("Database connection is closed")
var ErrNilState = fmt.Errorf("DbState cannot be nil")
Functions ¶
This section is empty.
Types ¶
type ClientController ¶
type ClientController interface { FindByID(string) (ClientModel, error) FindByName(string) (ClientModel, error) Create(ClientModel) (string, error) DeleteByID(string) error Batch(n, skip int64) ([]ClientModel, error) Count() (int64, error) }
ClientController defines database operations for the OAuth2 client model.
func NewClientController ¶
func NewClientController(state *MongoState) (ClientController, error)
NewClientController creates a MongoDB client controller using the provided database state.
type ClientModel ¶
type ClientModel struct { ID string `bson:"_id,omitempty"` Name string `bson:"name"` Description string `bson:"description"` ResponseType string `bson:"response_type"` RedirectURI string `bson:"redirect_uri"` Scope []string `bson:"scope"` Owner string `bson:"owner"` Key string `bson:"key"` CreatedAt int64 `bson:"createdAt"` TTL int64 `bson:"expireAfterSeconds"` }
ClientModel is the client schema.
type CollectionController ¶
type CollectionController struct {
// contains filtered or unexported fields
}
CollectionController is a controller struct template.
type Database ¶
type Database interface { Users() UserController Tokens() TokenController Clients() ClientController }
Database is an interface for accessing schema controllers.
type MongoClientController ¶
type MongoClientController CollectionController
MongoClientController implements ClientController using MongoDB.
func (*MongoClientController) Batch ¶
func (cc *MongoClientController) Batch(n, skip int64) ([]ClientModel, error)
func (*MongoClientController) Count ¶
func (cc *MongoClientController) Count() (int64, error)
func (*MongoClientController) Create ¶
func (cc *MongoClientController) Create(client ClientModel) (string, error)
Create a client and save it to the database.
func (*MongoClientController) DeleteByID ¶
func (cc *MongoClientController) DeleteByID(id string) error
DeleteByID deletes the client with the given id.
func (*MongoClientController) FindByID ¶
func (cc *MongoClientController) FindByID(id string) (ClientModel, error)
FindById finds a client program by its given ID.
func (*MongoClientController) FindByName ¶
func (cc *MongoClientController) FindByName(name string) (ClientModel, error)
FindByName finds a client program by its advertised name.
type MongoDatabase ¶
type MongoDatabase struct {
// contains filtered or unexported fields
}
MongoDatabase implements database using a MongoDB connnection.
func NewDatabase ¶
func NewDatabase(uri, name string) (*MongoDatabase, error)
NewDatabase implements the Database interface using an underlying MongoDB driver connection, where uri is the connection URI and name is the db name.
func (*MongoDatabase) Clients ¶
func (db *MongoDatabase) Clients() ClientController
Clients returns the database client controller. Returns nil if closed.
func (*MongoDatabase) Tokens ¶
func (db *MongoDatabase) Tokens() TokenController
Tokens returns the database token controller. Returns nil if closed.
func (*MongoDatabase) Users ¶
func (db *MongoDatabase) Users() UserController
Users returns the database user controller. Returns nil if closed.
type MongoState ¶
MongoState synchronizes database state and shares the MongoClient across the different schema controllers.
type MongoTokenController ¶
type MongoTokenController struct {
// contains filtered or unexported fields
}
MongoTokenController implements TokenController using MongoDB.
func (*MongoTokenController) CreateAccess ¶
func (cc *MongoTokenController) CreateAccess(tk TokenModel) (string, error)
func (*MongoTokenController) CreateAuth ¶
func (cc *MongoTokenController) CreateAuth(tk TokenModel) (string, error)
func (*MongoTokenController) CreateRefresh ¶
func (cc *MongoTokenController) CreateRefresh(tk TokenModel) (string, error)
func (*MongoTokenController) DeleteAccessByID ¶
func (cc *MongoTokenController) DeleteAccessByID(id string) error
func (*MongoTokenController) DeleteAuthByID ¶
func (cc *MongoTokenController) DeleteAuthByID(id string) error
func (*MongoTokenController) DeleteRefreshByID ¶
func (cc *MongoTokenController) DeleteRefreshByID(id string) error
func (*MongoTokenController) FindAccessByID ¶
func (cc *MongoTokenController) FindAccessByID(id string) (TokenModel, error)
func (*MongoTokenController) FindAuthByID ¶
func (cc *MongoTokenController) FindAuthByID(id string) (TokenModel, error)
func (*MongoTokenController) FindRefreshByID ¶
func (cc *MongoTokenController) FindRefreshByID(id string) (TokenModel, error)
type MongoUserController ¶
type MongoUserController struct {
// contains filtered or unexported fields
}
MongoUserController implements UserController on MongoDB.
func (*MongoUserController) Batch ¶
func (cc *MongoUserController) Batch(n, skip int64) ([]UserModel, error)
Page returns users in batches, with each p >= 0 returning the subsequent batch of 20 users.
func (*MongoUserController) Count ¶
func (cc *MongoUserController) Count() (int64, error)
Count returns the number of documents in the collection.
func (*MongoUserController) Create ¶
func (cc *MongoUserController) Create(usr UserModel) (string, error)
Create a user and save them to the database.
func (*MongoUserController) CreatePending ¶
func (cc *MongoUserController) CreatePending(usr PendingUserModel) ( string, error)
Create a pending user and save them to the database.
func (*MongoUserController) DeletePendingByID ¶
func (cc *MongoUserController) DeletePendingByID(id string) error
DeletePendingByID deletes the pending user with the given id.
func (*MongoUserController) FindByEmail ¶
func (cc *MongoUserController) FindByEmail(email string) (UserModel, error)
FindByEmail returns a user by their email address or error on failure.
func (*MongoUserController) FindByID ¶
func (cc *MongoUserController) FindByID(id string) (UserModel, error)
FindByID finds a registered user by their given ID.
func (*MongoUserController) FindPendingByEmail ¶
func (cc *MongoUserController) FindPendingByEmail(email string) ( PendingUserModel, error)
FindPendingByEmail finds a pending user by their registered email.
func (*MongoUserController) FindPendingByID ¶
func (cc *MongoUserController) FindPendingByID(id string) ( PendingUserModel, error)
FindPendingByID finds a pending user by their given ID.
type PendingUserModel ¶
type PendingUserModel struct { ID string `bson:"_id,omitempty"` Email string `bson:"email"` User UserModel `bson:"user"` TTL int64 `bson:"expireAfterSeconds"` }
PendingUserModel is a sign up request that is awaiting email verification.
type TokenController ¶
type TokenController interface { // Refresh tokens. FindRefreshByID(string) (TokenModel, error) CreateRefresh(TokenModel) (string, error) DeleteRefreshByID(string) error // Access tokens. FindAccessByID(string) (TokenModel, error) CreateAccess(TokenModel) (string, error) DeleteAccessByID(string) error // Authorization tokens/codes. FindAuthByID(string) (TokenModel, error) CreateAuth(TokenModel) (string, error) DeleteAuthByID(string) error }
TokenController defines database operations for the OAuth2 token model. It controls refresh and access tokens, as well as authorization codes.
func NewTokenController ¶
func NewTokenController(state *MongoState) (TokenController, error)
NewTokenController creates a MongoDB user controller using the provided database state.
type TokenModel ¶
type TokenModel struct { ID string `bson:"_id,omitempty"` ClientID string `bson:"client_id"` UserID string `bson:"user_id"` CreatedAt int64 `bson:"createdAt"` TTL int64 `bson:"expireAfterSeconds"` }
The Token schema is used for authentication codes, access tokens, and refresh tokens.
type UserController ¶
type UserController interface { // Registered/confirmed users. FindByEmail(string) (UserModel, error) FindByID(string) (UserModel, error) Update(UserModel) (int64, error) Create(UserModel) (string, error) Batch(n, skip int64) ([]UserModel, error) Count() (int64, error) // Pending users. FindPendingByID(string) (PendingUserModel, error) FindPendingByEmail(string) (PendingUserModel, error) CreatePending(PendingUserModel) (string, error) DeletePendingByID(string) error }
UserController defines database operations for the OAuth2 user model.
func NewUserController ¶
func NewUserController(state *MongoState) (UserController, error)
NewUserController creates a MongoDB user controller using the provided database state.
type UserModel ¶
type UserModel struct { ID string `bson:"_id,omitempty"` Email string `bson:"email"` Password string `bson:"password"` FirstName string `bson:"first_name"` LastName string `bson:"last_name"` Realms []string `bson:"realms"` LastVerified int64 `bson:"last_verified"` CreatedAt int64 `bson:"createdAt"` }
UserModel is the user schema.