identity

package
v0.0.0-...-bbaddd9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: AGPL-3.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const APIKeyMaxNameLength = 100
View Source
const APIKeySecretPrefix = "imgdd_"

APIKeySecretPrefix marks every API key secret so leaked keys are easy to recognize (e.g. by secret scanners).

Variables

View Source
var ErrAPIKeyNameInvalid = errors.New("api key name must be between 1 and 100 characters")
View Source
var ErrAPIKeyNotFound = errors.New("api key not found")

Functions

func AddUserToGroup

func AddUserToGroup(groupKey, userEmail string, dbConf *db.DBConfigDef) error

func CheckPasswordByUserId

func CheckPasswordByUserId(userId, password string, identityRepo IdentityRepo) bool

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func GetCurrentOrganizationUser

func GetCurrentOrganizationUser(cu ContextUserManager, c context.Context) *dm.OrganizationUser

func HashAPIKeySecret

func HashAPIKeySecret(secret string) string

HashAPIKeySecret returns the value stored in api_key_table.key_hash. Secrets carry 256 bits of randomness, so a fast hash is sufficient.

func HashPassword

func HashPassword(password string) (string, error)

func ResetPassword

func ResetPassword(
	identityRepo IdentityRepo,
	secretKey string,
	message string,
	newPassword string,
) error

func SendResetPasswordEmail

func SendResetPasswordEmail(
	emailBackend email.EmailBackend,
	secretKey string,
	user *dm.User,
	identityRepo IdentityRepo,
	baseURL *url.URL,
) error

Types

type AuthenticatedUser

type AuthenticatedUser struct {
	User *dm.User
}

type AuthenticationInfo

type AuthenticationInfo struct {
	AuthenticatedUser *AuthenticatedUser
	AuthorizedUser    *AuthorizedUser
}

type AuthorizedUser

type AuthorizedUser struct {
	OrganizationUser *dm.OrganizationUser
}

type ContextUserManager

type ContextUserManager interface {
	// GetAuthenticationInfo returns the authentication info from the given context.
	GetAuthenticationInfo(c context.Context) *AuthenticationInfo
	// WithAuthenticationInfo returns a new context with the given authentication info.
	WithAuthenticationInfo(c context.Context, authenticationInfo *AuthenticationInfo) context.Context
	// SetAuthenticationInfo sets the given authentication info to the given context.
	SetAuthenticationInfo(c context.Context, authenticationInfo *AuthenticationInfo)
}

type DBIdentityRepo

type DBIdentityRepo struct {
	db.RepoConn
}

func NewDBIdentityRepo

func NewDBIdentityRepo(conn *sql.DB) *DBIdentityRepo

func (*DBIdentityRepo) AddRoleToOrganizationUser

func (repo *DBIdentityRepo) AddRoleToOrganizationUser(organizationUserId, roleKey string) error

func (*DBIdentityRepo) CreateAPIKey

func (repo *DBIdentityRepo) CreateAPIKey(organizationUserId string, name string) (*dm.APIKey, string, error)

CreateAPIKey creates a key for the organization user and returns it along with the secret. The secret is only available here; it cannot be recovered.

func (*DBIdentityRepo) CreateOrganization

func (repo *DBIdentityRepo) CreateOrganization(name, slug string) (*dm.Organization, error)

func (*DBIdentityRepo) CreateUser

func (repo *DBIdentityRepo) CreateUser(email string, password string) (*dm.User, error)

func (*DBIdentityRepo) CreateUserWithOrganization

func (repo *DBIdentityRepo) CreateUserWithOrganization(
	email string, organizationName string, password string,
) (*dm.OrganizationUser, error)

func (*DBIdentityRepo) GetAllUsers

func (repo *DBIdentityRepo) GetAllUsers(limit int, offset int, search *string) ([]*dm.User, int)

func (*DBIdentityRepo) GetOrganizationById

func (repo *DBIdentityRepo) GetOrganizationById(id string) *dm.Organization

func (*DBIdentityRepo) GetOrganizationForUser

func (repo *DBIdentityRepo) GetOrganizationForUser(userId string, maybeOrganizationId string) (*dm.Organization, *dm.OrganizationUser)

func (*DBIdentityRepo) GetOrganizationUserByAPIKeySecret

func (repo *DBIdentityRepo) GetOrganizationUserByAPIKeySecret(secret string) *dm.OrganizationUser

GetOrganizationUserByAPIKeySecret resolves a secret to the organization user that owns it, or nil if the secret is unknown or revoked. It also records when the key was last used.

func (*DBIdentityRepo) GetOrganizationUserById

func (repo *DBIdentityRepo) GetOrganizationUserById(id string) *dm.OrganizationUser

func (*DBIdentityRepo) GetOrganizationUsersByIds

func (repo *DBIdentityRepo) GetOrganizationUsersByIds(ids []string) []*dm.OrganizationUser

func (*DBIdentityRepo) GetOrganizationUsersForUsers

func (repo *DBIdentityRepo) GetOrganizationUsersForUsers(userIds []string) (
	userIdToOrgUser map[string]*dm.UserWithOrganizationUsers,
	err error,
)

func (*DBIdentityRepo) GetOrganizationsByIds

func (repo *DBIdentityRepo) GetOrganizationsByIds(ids []string) []*dm.Organization

func (*DBIdentityRepo) GetUserByEmail

func (repo *DBIdentityRepo) GetUserByEmail(email string) *dm.User

func (*DBIdentityRepo) GetUserById

func (repo *DBIdentityRepo) GetUserById(id string) *dm.User

func (*DBIdentityRepo) GetUserPassword

func (repo *DBIdentityRepo) GetUserPassword(id string) string

func (*DBIdentityRepo) GetUsersByIds

func (repo *DBIdentityRepo) GetUsersByIds(ids []string) []*dm.User

func (*DBIdentityRepo) ListAPIKeys

func (repo *DBIdentityRepo) ListAPIKeys(organizationUserId string) ([]*dm.APIKey, error)

ListAPIKeys returns the organization user's keys that have not been revoked, newest first.

func (*DBIdentityRepo) RevokeAPIKey

func (repo *DBIdentityRepo) RevokeAPIKey(organizationUserId string, apiKeyId string) error

RevokeAPIKey revokes a key owned by the organization user. Revoking a key that does not exist, belongs to someone else, or is already revoked returns ErrAPIKeyNotFound.

func (*DBIdentityRepo) UpdateUserPassword

func (repo *DBIdentityRepo) UpdateUserPassword(id string, password string) error

func (*DBIdentityRepo) WithTransaction

func (repo *DBIdentityRepo) WithTransaction(tx *sql.Tx) db.DBRepo

type IdentityRepo

type IdentityRepo interface {
	CreateUserWithOrganization(email string, organizationName string, password string) (*dm.OrganizationUser, error)
	CreateUser(email string, password string) (*dm.User, error)
	AddRoleToOrganizationUser(organizationUserId string, roleKey string) error

	GetUserById(id string) *dm.User
	GetUsersByIds(ids []string) []*dm.User
	GetUserByEmail(email string) *dm.User

	// If maybeOrganizationId is not empty, it will be used as the organization ID.
	// Otherwise, the implementation should guess the best organization ID for the user.
	// E.g. if the user is a member of only one organization, that organization ID should be used.
	// If the user is a member of multiple organizations, the implementation should return nil.
	GetOrganizationForUser(userId string, maybeOrganizationId string) (*dm.Organization, *dm.OrganizationUser)

	GetOrganizationUsersForUsers(userIds []string) (map[string]*dm.UserWithOrganizationUsers, error)

	GetOrganizationUsersByIds(ids []string) []*dm.OrganizationUser
	GetOrganizationUserById(id string) *dm.OrganizationUser

	GetUserPassword(id string) string
	UpdateUserPassword(id string, password string) error

	// GetAllUsers returns a paginated list of users with optional search criteria.
	GetAllUsers(limit int, offset int, search *string) ([]*dm.User, int)

	CreateAPIKey(organizationUserId string, name string) (*dm.APIKey, string, error)
	ListAPIKeys(organizationUserId string) ([]*dm.APIKey, error)
	RevokeAPIKey(organizationUserId string, apiKeyId string) error
	// GetOrganizationUserByAPIKeySecret returns nil if the secret does not
	// belong to an active API key.
	GetOrganizationUserByAPIKeySecret(secret string) *dm.OrganizationUser
}

Jump to

Keyboard shortcuts

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