Documentation ¶
Index ¶
- Variables
- type ByFirstName
- type ByLastName
- type ByUsername
- type Filter
- type Manager
- type MongoManager
- func (m *MongoManager) Authenticate(username string, secret []byte) (*User, error)
- func (m *MongoManager) AuthenticateByID(id string, secret []byte) (*User, error)
- func (m *MongoManager) AuthenticateByUsername(username string, secret []byte) (*User, error)
- func (m *MongoManager) CreateUser(u *User) error
- func (m *MongoManager) DeleteUser(id string) error
- func (m *MongoManager) GetUser(id string) (*User, error)
- func (m *MongoManager) GetUserByUsername(username string) (*User, error)
- func (m *MongoManager) GetUsers(filters Filter) (map[string]User, error)
- func (m *MongoManager) GrantScopeToUser(id string, scope string) error
- func (m *MongoManager) RemoveScopeFromUser(id string, scope string) error
- func (m *MongoManager) UpdateUser(u *User) error
- type Storer
- type User
- func (u *User) AddScopes(addScopes ...string)
- func (u *User) AddTenantIDs(addTenantIDs ...string)
- func (u User) Authenticate(cleartext string, hasher fosite.Hasher) error
- func (u User) Equal(x User) bool
- func (u User) GetFullName() (fn string)
- func (u *User) GetHashedSecret() []byte
- func (u User) IsEmpty() bool
- func (u *User) RemoveScopes(removeScopes ...string)
- func (u *User) RemoveTenantIDs(removeTenants ...string)
- func (u *User) SetPassword(cleartext string, hasher fosite.Hasher) (err error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrUserExists = errors.New("user already exists")
)
Functions ¶
This section is empty.
Types ¶
type ByFirstName ¶ added in v0.7.1
type ByFirstName []User
ByFirstName enables sorting user accounts by First Name A-Z
func (ByFirstName) Len ¶ added in v0.7.1
func (u ByFirstName) Len() int
func (ByFirstName) Less ¶ added in v0.7.1
func (u ByFirstName) Less(i, j int) bool
func (ByFirstName) Swap ¶ added in v0.7.1
func (u ByFirstName) Swap(i, j int)
type ByLastName ¶ added in v0.7.1
type ByLastName []User
ByLastName enables sorting user accounts by Last Name A-Z
func (ByLastName) Len ¶ added in v0.7.1
func (u ByLastName) Len() int
func (ByLastName) Less ¶ added in v0.7.1
func (u ByLastName) Less(i, j int) bool
func (ByLastName) Swap ¶ added in v0.7.1
func (u ByLastName) Swap(i, j int)
type ByUsername ¶ added in v0.7.1
type ByUsername []User
ByUsername enables sorting user accounts by Username A-Z
func (ByUsername) Len ¶ added in v0.7.1
func (u ByUsername) Len() int
func (ByUsername) Less ¶ added in v0.7.1
func (u ByUsername) Less(i, j int) bool
func (ByUsername) Swap ¶ added in v0.7.1
func (u ByUsername) Swap(i, j int)
type MongoManager ¶
type MongoManager struct { // DB is the Mongo connection that holds the base session that can be copied and closed. DB *mgo.Database Hasher fosite.Hasher }
MongoManager manages the Mongo Session instance of a User. Implements user.Manager.
func (*MongoManager) Authenticate ¶
func (m *MongoManager) Authenticate(username string, secret []byte) (*User, error)
Authenticate wraps AuthenticateByUsername to allow users to be found via their username. Returns a user record if authentication is successful.
func (*MongoManager) AuthenticateByID ¶
func (m *MongoManager) AuthenticateByID(id string, secret []byte) (*User, error)
AuthenticateByID gets the stored user by ID and authenticates it using a hasher
func (*MongoManager) AuthenticateByUsername ¶
func (m *MongoManager) AuthenticateByUsername(username string, secret []byte) (*User, error)
AuthenticateByUsername gets the stored user by username and authenticates it using a hasher
func (*MongoManager) CreateUser ¶
func (m *MongoManager) CreateUser(u *User) error
CreateUser stores a new user into mongo
func (*MongoManager) DeleteUser ¶
func (m *MongoManager) DeleteUser(id string) error
DeleteUser removes a user from mongo
func (*MongoManager) GetUser ¶
func (m *MongoManager) GetUser(id string) (*User, error)
GetUser gets a user document that has been previously stored in mongo
func (*MongoManager) GetUserByUsername ¶
func (m *MongoManager) GetUserByUsername(username string) (*User, error)
GetUserByUsername gets a user document by searching for a username that has been previously stored in mongo
func (*MongoManager) GetUsers ¶
func (m *MongoManager) GetUsers(filters Filter) (map[string]User, error)
GetUsers returns a map of IDs mapped to a User object that are stored in mongo
func (*MongoManager) GrantScopeToUser ¶
func (m *MongoManager) GrantScopeToUser(id string, scope string) error
GrantScopeToUser adds a scope to a user if it doesn't already exist in the mongo record
func (*MongoManager) RemoveScopeFromUser ¶
func (m *MongoManager) RemoveScopeFromUser(id string, scope string) error
RemoveScopeFromUser takes a scoped right away from the given user.
func (*MongoManager) UpdateUser ¶
func (m *MongoManager) UpdateUser(u *User) error
UpdateUser updates a user record. This is done using the equivalent of an object replace.
type Storer ¶
type Storer interface { GetConcreteUser(id string) (*User, error) GetUser(id string) (User, error) GetUsers() (map[string]User, error) CreateUser(u *User) error UpdateUser(u *User) error DeleteUser(id string) error GrantScope(scope string) error RemoveScope(scope string) error AuthenticateByID(id string, secret []byte) (*User, error) AuthenticateByUsername(username string, secret []byte) (*User, error) }
Storer provides a definition of specific methods that are required to store a User in a data store.
type User ¶
type User struct { // ID is the uniquely assigned uuid that references the user ID string `bson:"_id" json:"id" xml:"id"` // PersonID is a uniquely assigned uuid that references a person within the system. // This enables applications where an external person data store is present. This helps in multi-tenanted // situations where the person is unique, but the underlying user accounts can exist per tenant. PersonID string `bson:"personID" json:"personID" xml:"personID"` // The Tenant IDs that the user has been given rights to access. // This helps in multi-tenanted situations where a user can be given explicit cross-tenant access. TenantIDs []string `bson:"tenantIDs,omitempty" json:"tenantIDs,omitempty" xml:"tenantIDs,omitempty"` // Username is used to authenticate a user Username string `bson:"username" json:"username" xml:"username"` // Password of the user - will be a hash based on your fosite selected hasher // If using this model directly in an API, be sure to clear the password out when marshaling to json/xml Password string `bson:"password,omitempty" json:"password,omitempty" xml:"password,omitempty"` // Scopes contains the scopes that have been granted to Scopes []string `bson:"scopes" json:"scopes" xml:"scopes"` // FirstName stores the user's Last Name FirstName string `bson:"firstName" json:"firstName" xml:"firstName"` // LastName stores the user's Last Name LastName string `bson:"lastName" json:"lastName" xml:"lastName"` // ProfileURI is a pointer to where their profile picture lives ProfileURI string `bson:"profileUri" json:"profileUri,omitempty" xml:"profileUri,omitempty"` // Disabled specifies whether the user has been disallowed from signing in Disabled bool `bson:"disabled" json:"disabled" xml:"disabled"` }
User provides the specific types for storing, editing, deleting and retrieving a User record in mongo.
func (*User) AddTenantIDs ¶ added in v0.4.0
AddTenantIDs adds a single or multiple tenantIDs to the given user
func (User) Authenticate ¶
Authenticate compares a cleartext string against the user's
func (User) Equal ¶ added in v0.4.2
Equal enables checking equality as having a byte array in a struct stop allowing equality checks.
func (User) GetFullName ¶
GetFullName concatenates the User's First Name and Last Name for templating purposes
func (*User) GetHashedSecret ¶
GetHashedSecret returns the Users's Hashed Secret as a byte array
func (*User) RemoveScopes ¶ added in v0.4.0
AddScopes adds multiple scopes to the given user
func (*User) RemoveTenantIDs ¶ added in v0.4.0
RemoveTenants removes a single or multiple tenantIDs from the given user