consent

package
v0.117.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const SourceSignup = "signup"

Variables

View Source
var (
	// ErrUnknownDocuments is returned for an id this deployment does not
	// configure, which is how a mismatch with the client's list surfaces.
	ErrUnknownDocuments = errors.New("unknown consent document ids")

	// ErrMissingDocuments is returned when the ids do not cover every configured
	// document. All of them are required at signup.
	ErrMissingDocuments = errors.New("missing consent document ids")

	// ErrInvalidGrant is returned when a grant is missing something the record needs.
	ErrInvalidGrant = errors.New("invalid consent grant")

	// ErrConsentExists is returned when a user already has a signup record.
	ErrConsentExists = errors.New("a consent record already exists for this user")
)

Functions

This section is empty.

Types

type AuditRecordRepository

type AuditRecordRepository interface {
	Create(ctx context.Context, auditRecord models.AuditRecord) (models.AuditRecord, error)
}

type Config

type Config struct {
	// Enabled switches the whole feature off by default.
	Enabled bool `yaml:"enabled" mapstructure:"enabled" default:"false"`

	Documents map[string]DocumentConfig `yaml:"documents" mapstructure:"documents"`
}

Config lists the documents a deployment asks people to accept before an account is created. It sits at app.consent, beside app.authentication.

Keyed by document id rather than a list, matching how authenticate.Config keys oidc_config: the key enforces unique ids and stays env-overridable. Every document is required at signup, so there is no per-document flag.

func (Config) Validate

func (c Config) Validate() error

Validate runs at boot, so bad config stops the server rather than surfacing on someone's signup. A disabled block is not checked at all: nothing reads it, so a half-written map is only an error once consent is turned on.

type Consent struct {
	ID           string
	UserID       string
	UserEmail    string
	Documents    []Document
	Source       string
	AuthStrategy string
	// IPAddress is empty when the deployment sets no client IP header.
	IPAddress string
	// ConsentedAt is when the user accepted, not when the row was written.
	ConsentedAt time.Time
	CreatedAt   time.Time
}

Consent is an immutable record of one act of accepting documents

type Document

type Document struct {
	ID      string
	Title   string
	Version string
	URL     string
}

Document is one document a user has to accept before an account is created.

type DocumentConfig

type DocumentConfig struct {
	Title string `yaml:"title" mapstructure:"title"`
	// Version is copied into the consent record and compared for equality only.
	Version string `yaml:"version" mapstructure:"version"`
	URL     string `yaml:"url" mapstructure:"url"`
}

type GrantRequest

type GrantRequest struct {
	UserID       string
	UserEmail    string
	Documents    []Document
	Source       string
	AuthStrategy string
	IPAddress    string
	ConsentedAt  time.Time
}

type Service

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

func NewService

func NewService(logger *slog.Logger, config Config,
	auditRecordRepository AuditRecordRepository) *Service

func (Service) Documents

func (s Service) Documents() []Document

Documents returns every configured document, ordered by id

func (Service) Enabled

func (s Service) Enabled() bool

Enabled reports whether this deployment asks for consent at all

func (Service) PrepareGrant

func (s Service) PrepareGrant(req GrantRequest) (Consent, error)

func (Service) RecordGranted

func (s Service) RecordGranted(ctx context.Context, granted Consent)

RecordGranted writes the audit record after the commit

func (Service) Resolve

func (s Service) Resolve(ids []string) ([]Document, error)

Resolve maps ids to their config snapshots and rejects unknown ones Disabled, it resolves nothing and rejects nothing, so the ids are ignored rather than refused.

func (Service) ResolveAll

func (s Service) ResolveAll(ids []string) ([]Document, error)

ResolveAll is Resolve plus the completeness rule: the ids must cover every configured document, no more and no less

Jump to

Keyboard shortcuts

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