identityservice

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package identityservice owns remote account and credential policies.

Index

Constants

View Source
const (
	PurposeCollector     Purpose = "collector"
	PurposeAPI           Purpose = "api"
	SessionLifetime              = 7 * 24 * time.Hour
	DefaultTokenLifetime         = 90 * 24 * time.Hour
	MaximumTokenLifetime         = 365 * 24 * time.Hour
)

Variables

View Source
var (
	ErrAuthentication = errors.New("invalid credentials")
	ErrInvalidInput   = errors.New("invalid identity input")
	ErrConflict       = errors.New("username already exists")
	ErrNotFound       = errors.New("identity not found")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	ID       string
	Username string
}

type CreatedToken

type CreatedToken struct {
	Token
	Secret string
}

type PasswordCredential

type PasswordCredential struct {
	Account Account
	Hash    string
}

type Purpose

type Purpose string

type Service

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

func New

func New(store Store) *Service

func (*Service) Accounts

func (service *Service) Accounts(ctx context.Context) ([]Account, error)

func (*Service) AuthenticateSession

func (service *Service) AuthenticateSession(ctx context.Context, secret string) (Session, error)

func (*Service) AuthenticateToken

func (service *Service) AuthenticateToken(ctx context.Context, secret string) (TokenIdentity, error)

func (*Service) Bootstrap

func (service *Service) Bootstrap(ctx context.Context, username, password string) (Account, error)

func (*Service) ChangePassword

func (service *Service) ChangePassword(ctx context.Context, accountID, current, password string) error

func (*Service) CreateToken

func (service *Service) CreateToken(ctx context.Context, accountID, name string, purpose Purpose, expires time.Time) (CreatedToken, error)

func (*Service) Login

func (service *Service) Login(ctx context.Context, username, password string) (Session, error)

func (*Service) Logout

func (service *Service) Logout(ctx context.Context, secret string) error

func (*Service) Provision

func (service *Service) Provision(ctx context.Context, username, password string) (Account, error)

func (*Service) ResetPassword

func (service *Service) ResetPassword(ctx context.Context, username, password string) error

func (*Service) RevokeToken

func (service *Service) RevokeToken(ctx context.Context, accountID, tokenID string) error

func (*Service) Tokens

func (service *Service) Tokens(ctx context.Context, accountID string) ([]Token, error)

type Session

type Session struct {
	Account   Account
	Secret    string
	CSRFToken string
	ExpiresAt time.Time
}

type Store

type Store interface {
	CreateAccount(context.Context, Account, string, bool, time.Time) (Account, error)
	AccountPassword(context.Context, string) (PasswordCredential, error)
	AccountPasswordByID(context.Context, string) (PasswordCredential, error)
	ReplacePassword(context.Context, string, string, string) error
	CreateSession(context.Context, string, string, string, string, time.Time) error
	ResolveSession(context.Context, string, time.Time) (Session, error)
	DeleteSession(context.Context, string) error
	CreateIdentityToken(context.Context, string, Token, string) error
	IdentityTokens(context.Context, string) ([]Token, error)
	DeleteIdentityToken(context.Context, string, string) error
	ResolveIdentityToken(context.Context, string, time.Time) (TokenIdentity, error)
	IdentityAccounts(context.Context) ([]Account, error)
}

Store operations preserve credential races atomically. Password replacement revokes sessions in its transaction; session creation compares the verified hash.

type Token

type Token struct {
	ID         string
	Name       string
	Purpose    Purpose
	CreatedAt  time.Time
	LastUsedAt *time.Time
	ExpiresAt  time.Time
}

type TokenIdentity

type TokenIdentity struct {
	Account   Account
	Purpose   Purpose
	ExpiresAt time.Time
}

Jump to

Keyboard shortcuts

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