Documentation ¶
Overview ¶
Package account contains the code to manage users and integrate authenthication functionalities from other identity providers.
Index ¶
- Constants
- func IdentityFilterByID(identityID uuid.UUID) func(db *gorm.DB) *gorm.DB
- func IdentityFilterByProfileURL(profileURL string) func(db *gorm.DB) *gorm.DB
- func IdentityFilterByProviderType(providerType string) func(db *gorm.DB) *gorm.DB
- func IdentityFilterByRegistrationCompleted(registrationCompleted bool) func(db *gorm.DB) *gorm.DB
- func IdentityFilterByUserID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB
- func IdentityFilterByUsername(username string) func(db *gorm.DB) *gorm.DB
- func IdentityWithUser() func(db *gorm.DB) *gorm.DB
- func UserFilterByEmail(email string) func(db *gorm.DB) *gorm.DB
- func UserFilterByID(userID uuid.UUID) func(db *gorm.DB) *gorm.DB
- type ContextInformation
- type GormIdentityRepository
- func (m *GormIdentityRepository) CheckExists(ctx context.Context, id string) error
- func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) error
- func (m *GormIdentityRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (m *GormIdentityRepository) First(funcs ...func(*gorm.DB) *gorm.DB) (*Identity, error)
- func (m *GormIdentityRepository) IsValid(ctx context.Context, id uuid.UUID) bool
- func (m *GormIdentityRepository) List(ctx context.Context) ([]Identity, error)
- func (m *GormIdentityRepository) Load(ctx context.Context, id uuid.UUID) (*Identity, error)
- func (m *GormIdentityRepository) Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error)
- func (m *GormIdentityRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]Identity, error)
- func (m *GormIdentityRepository) Save(ctx context.Context, model *Identity) error
- func (m *GormIdentityRepository) Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error)
- func (m *GormIdentityRepository) TableName() string
- type GormUserRepository
- func (m *GormUserRepository) CheckExists(ctx context.Context, id string) error
- func (m *GormUserRepository) Create(ctx context.Context, u *User) error
- func (m *GormUserRepository) Delete(ctx context.Context, id uuid.UUID) error
- func (m *GormUserRepository) List(ctx context.Context) ([]User, error)
- func (m *GormUserRepository) Load(ctx context.Context, id uuid.UUID) (*User, error)
- func (m *GormUserRepository) Query(funcs ...func(*gorm.DB) *gorm.DB) ([]User, error)
- func (m *GormUserRepository) Save(ctx context.Context, model *User) error
- func (m *GormUserRepository) TableName() string
- type Identity
- type IdentityRepository
- type NullUUID
- type User
- type UserRepository
Constants ¶
const ( // KeycloakIDP is the name of the main Keycloak Identity Provider KeycloakIDP string = "kc" )
Variables ¶
This section is empty.
Functions ¶
func IdentityFilterByID ¶
IdentityFilterByID is a gorm filter for Identity ID.
func IdentityFilterByProfileURL ¶
IdentityFilterByProfileURL is a gorm filter by 'profile_url'
func IdentityFilterByProviderType ¶
IdentityFilterByProviderType is a gorm filter by 'provider_type'
func IdentityFilterByRegistrationCompleted ¶
IdentityFilterByRegistrationCompleted is a gorm filter by 'registration_completed'
func IdentityFilterByUserID ¶
IdentityFilterByUserID is a gorm filter for a Belongs To relationship.
func IdentityFilterByUsername ¶
IdentityFilterByUsername is a gorm filter by 'username'
func IdentityWithUser ¶
IdentityWithUser is a gorm filter for preloading the User relationship.
func UserFilterByEmail ¶
UserFilterByEmail is a gorm filter for User ID.
Types ¶
type ContextInformation ¶
type ContextInformation map[string]interface{}
func (ContextInformation) Equal ¶
func (f ContextInformation) Equal(u convert.Equaler) bool
Equal returns true if two ContextInformation objects are equal; otherwise false is returned. TODO: (kwk) think about a better comparison for ContextInformation map.
func (*ContextInformation) Scan ¶
func (j *ContextInformation) Scan(src interface{}) error
type GormIdentityRepository ¶
type GormIdentityRepository struct {
// contains filtered or unexported fields
}
GormIdentityRepository is the implementation of the storage interface for Identity.
func NewIdentityRepository ¶
func NewIdentityRepository(db *gorm.DB) *GormIdentityRepository
NewIdentityRepository creates a new storage type.
func (*GormIdentityRepository) CheckExists ¶
func (m *GormIdentityRepository) CheckExists(ctx context.Context, id string) error
CheckExists returns nil if the given ID exists otherwise returns an error
func (*GormIdentityRepository) Create ¶
func (m *GormIdentityRepository) Create(ctx context.Context, model *Identity) error
Create creates a new record.
func (*GormIdentityRepository) First ¶
First returns the first Identity element that matches the given criteria
func (*GormIdentityRepository) List ¶
func (m *GormIdentityRepository) List(ctx context.Context) ([]Identity, error)
List return all user identities
func (*GormIdentityRepository) Load ¶
Load returns a single Identity as a Database Model This is more for use internally, and probably not what you want in your controllers
func (*GormIdentityRepository) Lookup ¶
func (m *GormIdentityRepository) Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error)
Lookup looks for an existing identity with the given `profileURL` or creates a new one
func (*GormIdentityRepository) Save ¶
func (m *GormIdentityRepository) Save(ctx context.Context, model *Identity) error
Save modifies a single record.
func (*GormIdentityRepository) Search ¶
func (m *GormIdentityRepository) Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error)
Search searches for Identites where FullName like %q% or users.email like %q% or users.username like %q%
func (*GormIdentityRepository) TableName ¶
func (m *GormIdentityRepository) TableName() string
TableName overrides the table name settings in Gorm to force a specific table name in the database.
type GormUserRepository ¶
type GormUserRepository struct {
// contains filtered or unexported fields
}
GormUserRepository is the implementation of the storage interface for User.
func (*GormUserRepository) CheckExists ¶
func (m *GormUserRepository) CheckExists(ctx context.Context, id string) error
CheckExists returns nil if the given ID exists otherwise returns an error
func (*GormUserRepository) Create ¶
func (m *GormUserRepository) Create(ctx context.Context, u *User) error
Create creates a new record.
func (*GormUserRepository) List ¶
func (m *GormUserRepository) List(ctx context.Context) ([]User, error)
List return all users
func (*GormUserRepository) Load ¶
Load returns a single User as a Database Model This is more for use internally, and probably not what you want in your controllers
func (*GormUserRepository) Save ¶
func (m *GormUserRepository) Save(ctx context.Context, model *User) error
Save modifies a single record
func (*GormUserRepository) TableName ¶
func (m *GormUserRepository) TableName() string
TableName overrides the table name settings in Gorm to force a specific table name in the database.
type Identity ¶
type Identity struct { gormsupport.Lifecycle // This is the ID PK field. For identities provided by Keycloak this ID equals to the Keycloak. For other types of IDP (github, oso, etc) this ID is generated automaticaly ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"` // The username of the Identity Username string // Whether username has been updated. RegistrationCompleted bool `gorm:"column:registration_completed"` // ProviderType The type of provider, such as "keycloak", "github", "oso", etc ProviderType string `gorm:"column:provider_type"` // the URL of the profile on the remote work item service ProfileURL *string `gorm:"column:profile_url"` // Link to User UserID NullUUID `sql:"type:uuid"` User User }
Identity describes a federated identity provided by Identity Provider (IDP) such as Keycloak, GitHub, OSO, etc. One User account can have many Identities
func (Identity) GetETagData ¶
func (m Identity) GetETagData() []interface{}
GetETagData returns the field values to use to generate the ETag
func (Identity) GetLastModified ¶
GetLastModified returns the last modification time
type IdentityRepository ¶
type IdentityRepository interface { repository.Exister Load(ctx context.Context, id uuid.UUID) (*Identity, error) Create(ctx context.Context, identity *Identity) error Lookup(ctx context.Context, username, profileURL, providerType string) (*Identity, error) Save(ctx context.Context, identity *Identity) error Delete(ctx context.Context, id uuid.UUID) error Query(funcs ...func(*gorm.DB) *gorm.DB) ([]Identity, error) List(ctx context.Context) ([]Identity, error) IsValid(context.Context, uuid.UUID) bool Search(ctx context.Context, q string, start int, limit int) ([]Identity, int, error) }
IdentityRepository represents the storage interface.
type NullUUID ¶
NullUUID can be used with the standard sql package to represent a UUID value that can be NULL in the database
type User ¶
type User struct { gormsupport.Lifecycle ID uuid.UUID `sql:"type:uuid default uuid_generate_v4()" gorm:"primary_key"` // This is the ID PK field Email string `sql:"unique_index"` // This is the unique email field FullName string // The fullname of the User ImageURL string // The image URL for the User Bio string // The bio of the User URL string // The URL of the User Company string // The (optional) Company of the User Identities []Identity // has many Identities from different IDPs ContextInformation ContextInformation `sql:"type:jsonb"` // context information of the user activity }
User describes a User account. A few identities can be assosiated with one user account
func (User) GetETagData ¶
func (m User) GetETagData() []interface{}
GetETagData returns the field values to use to generate the ETag
func (User) GetLastModified ¶
GetLastModified returns the last modification time
type UserRepository ¶
type UserRepository interface { repository.Exister Load(ctx context.Context, ID uuid.UUID) (*User, error) Create(ctx context.Context, u *User) error Save(ctx context.Context, u *User) error List(ctx context.Context) ([]User, error) Delete(ctx context.Context, ID uuid.UUID) error Query(funcs ...func(*gorm.DB) *gorm.DB) ([]User, error) }
UserRepository represents the storage interface.
func NewUserRepository ¶
func NewUserRepository(db *gorm.DB) UserRepository
NewUserRepository creates a new storage type.