auth

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const IdentityProviderOIDC = "oidc"

Variables

View Source
var (
	ErrOIDCExchange        = errors.New("oidc authorization code exchange failed")
	ErrOIDCInvalidToken    = errors.New("oidc ID token is invalid")
	ErrOIDCInvalidNonce    = errors.New("oidc nonce is invalid")
	ErrOIDCMissingEmail    = errors.New("oidc ID token does not contain an email")
	ErrOIDCUnverifiedEmail = errors.New("oidc email is not verified")
)
View Source
var (
	ErrEmailNotAllowed = errors.New("email is not allowed")
	ErrInvalidLink     = errors.New("magic link is invalid or expired")
	ErrInvalidSession  = errors.New("web session is invalid or expired")
	ErrMissingStore    = errors.New("auth store is required")
	ErrMissingSender   = errors.New("magic link sender is required")
)

Functions

This section is empty.

Types

type Allowlist added in v0.48.0

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

func NewAllowlist added in v0.48.0

func NewAllowlist(emails []string, domains []string) (*Allowlist, error)

func (*Allowlist) Allows added in v0.48.0

func (a *Allowlist) Allows(email string, verified bool) bool

type Config

type Config struct {
	AllowedEmails []string
	LinkTTL       time.Duration
	SessionTTL    time.Duration
	PublicURL     string
}

type Identity added in v0.48.0

type Identity struct {
	Subject       string
	Email         string
	EmailVerified bool
}

type IdentityProvider added in v0.48.0

type IdentityProvider interface {
	AuthorizationURL(state string, nonce string, verifier string) string
	Exchange(context.Context, string, string, string) (Identity, error)
}

func NewIdentityProvider added in v0.48.0

func NewIdentityProvider(ctx context.Context, provider string, cfg OIDCConfig) (IdentityProvider, error)
type MagicLink struct {
	TokenHash string
	Email     string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type MagicLinkConsumption

type MagicLinkConsumption struct {
	TokenHash        string
	SessionHash      string
	SessionExpiresAt time.Time
	Now              time.Time
}

type MagicLinkStore added in v0.48.0

type MagicLinkStore interface {
	CreateMagicLink(context.Context, MagicLink) error
	ConsumeMagicLink(context.Context, MagicLinkConsumption) (Session, error)
}

type Message

type Message struct {
	To        string
	URL       string
	ExpiresAt time.Time
}

type OIDCConfig added in v0.48.0

type OIDCConfig struct {
	IssuerURL    string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
}

type Option

type Option func(*Service)

func WithClock

func WithClock(now func() time.Time) Option

func WithRandom

func WithRandom(reader io.Reader) Option

type SMTPConfig

type SMTPConfig struct {
	Host     string
	Port     int
	Username string
	Password string
	From     string
}

type Sender

type Sender interface {
	SendMagicLink(context.Context, Message) error
}

func NewSMTPSender

func NewSMTPSender(cfg SMTPConfig) (Sender, error)

type Service

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

func NewService

func NewService(cfg Config, store Store, sender Sender, opts ...Option) (*Service, error)

func NewSessionService added in v0.48.0

func NewSessionService(cfg SessionConfig, store SessionStore, opts ...Option) (*Service, error)

func (*Service) Authenticate

func (s *Service) Authenticate(ctx context.Context, token string) (Session, error)
func (s *Service) ConsumeLink(ctx context.Context, token string) (string, Session, error)
func (s *Service) CreateLink(ctx context.Context, email string, next string) (string, time.Time, error)

func (*Service) CreateSession

func (s *Service) CreateSession(ctx context.Context, email string) (string, Session, error)
func (s *Service) RequestLink(ctx context.Context, email string, next string) error

func (*Service) SecureCookie

func (s *Service) SecureCookie() bool

type Session

type Session struct {
	Email     string
	ExpiresAt time.Time
}

type SessionConfig added in v0.48.0

type SessionConfig struct {
	SessionTTL time.Duration
	PublicURL  string
}

type SessionRecord

type SessionRecord struct {
	TokenHash string
	Email     string
	ExpiresAt time.Time
	CreatedAt time.Time
}

type SessionStore added in v0.48.0

type SessionStore interface {
	CreateWebSession(context.Context, SessionRecord) error
	WebSession(context.Context, string, time.Time) (Session, error)
}

type Store

type Store interface {
	SessionStore
	MagicLinkStore
}

Jump to

Keyboard shortcuts

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