iam

package
v0.0.0-...-0ff5b8e Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrForbidden = errors.New("forbidden")
View Source
var ErrUnauthorized = errors.New("unauthorized")

Functions

func CheckPassword

func CheckPassword(ctx context.Context, store PasswordStore, userID core.ID, password string) error

func PutPrincipal

func PutPrincipal(ctx context.Context, op Principal) context.Context

PutPrincipal stores a Principal in the context.

func SetPassword

func SetPassword(ctx context.Context, store PasswordStore, userID core.ID, password string) error

Types

type Action

type Action string

type AllowAll

type AllowAll struct{}

AllowAll is a Guard that permits all actions.

func (AllowAll) Check

type AllowNone

type AllowNone struct{}

AllowNone is a Guard that denies all actions.

func (AllowNone) Check

type Guard

type Guard interface {
	Check(context.Context, Action, core.Path) error
}

type OAuthStore

type OAuthStore interface {
	// AddProvider adds an OAuth provider to a user
	AddProvider(ctx context.Context, userID core.ID, provider, providerID string) error
	GetUserByProvider(ctx context.Context, provider, providerID string) (*User, error)
}

type PasswordHash

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

PasswordHash is an opaque type representing a hashed password. It implements driver.Valuer and sql.Scanner for database storage.

func NewPasswordHash

func NewPasswordHash(hash string) PasswordHash

func (PasswordHash) MarshalJSON

func (p PasswordHash) MarshalJSON() ([]byte, error)

func (PasswordHash) MarshalText

func (p PasswordHash) MarshalText() ([]byte, error)

func (*PasswordHash) Scan

func (p *PasswordHash) Scan(src any) error

func (PasswordHash) String

func (p PasswordHash) String() string

func (*PasswordHash) UnmarshalJSON

func (p *PasswordHash) UnmarshalJSON([]byte) error

func (*PasswordHash) UnmarshalText

func (p *PasswordHash) UnmarshalText([]byte) error

func (PasswordHash) Value

func (p PasswordHash) Value() (driver.Value, error)

type PasswordStore

type PasswordStore interface {
	SetHash(ctx context.Context, userID core.ID, hash PasswordHash) error
	GetHash(ctx context.Context, userID core.ID) (PasswordHash, error)
}

PasswordStore is implemented by the app to persist password hashes.

type Principal

type Principal interface {
	PrincipalID() core.ID
}

func Anonymous

func Anonymous() Principal

func GetPrincipal

func GetPrincipal(ctx context.Context) Principal

GetPrincipal retrieves a Principal from the context. If not found, returns a zero value (anonymous) principal.

type SessionReader

type SessionReader interface {
	Get(ctx context.Context) (core.ID, error)
}

type SessionStore

type SessionStore interface {
	SessionReader
	Put(ctx context.Context, id core.ID) error
	Destroy(ctx context.Context) error
}

type User

type User struct {
	ID    core.ID
	Email string
}

type UserStore

type UserStore interface {
	Save(ctx context.Context, user *User) (created bool, err error)

	// GetUserByEmail gets a user by email.
	// Returns core.ErrNotFound if user doesn't exist
	GetByEmail(ctx context.Context, email string) (*User, error)

	// Get gets a user by ID.
	// Returns core.ErrNotFound if user doesn't exist
	Get(ctx context.Context, id core.ID) (*User, error)
}

UserStore provides access to user data

Source Files

  • errors.go
  • guard.go
  • oauth.go
  • passwords.go
  • principal.go
  • session.go
  • users.go

Jump to

Keyboard shortcuts

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