identity

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package identity provides reusable user identity and role management.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid indicates validation failure.
	ErrInvalid = errors.New("invalid request")
	// ErrNotFound indicates no user matched query.
	ErrNotFound = errors.New("user not found")
	// ErrConflict indicates write conflicts such as duplicate identities.
	ErrConflict = errors.New("user conflict")
	// ErrInternal is used as a defensive fallback for unknown failures.
	ErrInternal = errors.New("internal error")
)

Functions

func MigrationsFS

func MigrationsFS() (fs.FS, error)

MigrationsFS returns the embedded identity migrations filesystem.

func MustMigrationsFS

func MustMigrationsFS() fs.FS

MustMigrationsFS returns the embedded migrations filesystem or panics.

Types

type Config

type Config struct {
	DefaultLanguage  string
	AllowedLanguages []string
}

Config controls identity defaults and validation.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a baseline configuration for identity services.

type EnsureInput

type EnsureInput struct {
	Provider     string
	Subject      string
	Email        string
	FirstName    string
	LastName     string
	Language     string
	DefaultRoles []string
}

EnsureInput contains the identity attributes coming from auth tokens.

type Repo

type Repo interface {
	Create(ctx context.Context, u *User) error
	GetByID(ctx context.Context, id string) (*User, error)
	GetByIdentity(ctx context.Context, provider, subject string) (*User, error)
	Update(ctx context.Context, u *User) error
	ListRoles(ctx context.Context, userID string) ([]string, error)
	ReplaceRoles(ctx context.Context, userID string, roles []string, at time.Time) error
}

Repo defines persistence requirements for the identity service.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service encapsulates reusable identity lifecycle logic.

func New

func New(repo Repo, tx ports.TxManager, log ports.Logger, clk ports.Clock, ids ports.IDGen, cfg Config) *Service

New constructs a Service with configurable defaults.

func NewDefault

func NewDefault(repo Repo, tx ports.TxManager, log ports.Logger, clk ports.Clock, ids ports.IDGen) *Service

NewDefault constructs a Service with baseline defaults.

func (*Service) EnsureUser

func (s *Service) EnsureUser(ctx context.Context, in EnsureInput) (*User, error)

EnsureUser maps an external identity to a local profile, creating one on first login.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (*User, error)

Get returns a user by internal ID.

func (*Service) ReplaceRoles

func (s *Service) ReplaceRoles(ctx context.Context, in UpdateRolesInput) (*User, error)

ReplaceRoles overwrites the roles assigned to a user.

func (*Service) UpdateProfile

func (s *Service) UpdateProfile(ctx context.Context, in UpdateProfileInput) (*User, error)

UpdateProfile mutates allowed profile fields.

type UpdateProfileInput

type UpdateProfileInput struct {
	UserID            string
	PreferredLanguage *string
}

UpdateProfileInput lists supported profile changes initiated by the user.

type UpdateRolesInput

type UpdateRolesInput struct {
	UserID string
	Roles  []string
}

UpdateRolesInput replaces the roles assigned to a user.

type User

type User struct {
	ID                string
	Provider          string
	Subject           string
	Email             string
	FirstName         string
	LastName          string
	PreferredLanguage string
	Roles             []string
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

User stores the local identity profile metadata.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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