Versions in this module Expand all Collapse all v0 v0.1.1 Oct 15, 2026 v0.1.0 Mar 29, 2026 Changes in this version + var ErrCodeGenerationFailed = errors.New("authkit: code generation failed") + var ErrIDGenerationFailed = errors.New("authkit: id generation failed") + var ErrIdentityLinkNotFound = errors.New("authkit: identity link not found") + var ErrIntentAlreadyRedeemed = errors.New("authkit: intent already redeemed") + var ErrIntentExpired = errors.New("authkit: intent expired") + var ErrIntentNotActive = errors.New("authkit: intent is not active") + var ErrIntentNotFound = errors.New("authkit: intent not found") + var ErrIntentRedemptionLimitReached = errors.New("authkit: intent redemption limit reached") + var ErrInvalidInput = errors.New("authkit: invalid input") + var ErrLoginLinkExpired = errors.New("authkit: login link expired") + var ErrLoginLinkInvalid = errors.New("authkit: login link is invalid") + var ErrLoginLinkNotConfigured = errors.New("authkit: login link is not configured") + var ErrSessionExpired = errors.New("authkit: session expired") + var ErrSessionNotFound = errors.New("authkit: session not found") + var ErrSubjectUnresolved = errors.New("authkit: subject unresolved") + type AccountLink struct + AppUserID string + Identity Identity + LinkedAt time.Time + type AudienceResolver interface + ResolveAudience func(ctx context.Context, messenger Messenger, identity *Identity) (string, error) + type AudienceResolverFunc func(ctx context.Context, messenger Messenger, identity *Identity) (string, error) + func (f AudienceResolverFunc) ResolveAudience(ctx context.Context, messenger Messenger, identity *Identity) (string, error) + type AuthIntent struct + Audience string + Code string + ConsumedAt *time.Time + CreatedAt time.Time + ExpiresAt *time.Time + ID string + Identity *Identity + MaxRedemptions int + Messenger Messenger + Metadata map[string]string + RedemptionCount int + RedemptionMode IntentRedemptionMode + State IntentState + SubjectID string + type AuthService struct + func NewAuthService(intentStore IntentStore, linkStore LinkStore, sessionIssuer SessionIssuer, ...) (*AuthService, error) + func (s *AuthService) CreateIntent(ctx context.Context, in CreateIntentInput) (AuthIntent, error) + func (s *AuthService) CreateLoginLink(ctx context.Context, in CreateLoginLinkInput) (CreateLoginLinkOutput, error) + func (s *AuthService) RedeemIntent(ctx context.Context, in RedeemIntentInput) (WebSession, error) + func (s *AuthService) RedeemLoginLink(ctx context.Context, in RedeemLoginLinkInput) (WebSession, error) + type BotFirstService interface + CreateLoginLink func(ctx context.Context, in CreateLoginLinkInput) (CreateLoginLinkOutput, error) + RedeemLoginLink func(ctx context.Context, in RedeemLoginLinkInput) (WebSession, error) + type ChannelAdapter interface + DeliverIntent func(ctx context.Context, identity Identity, intent AuthIntent) error + type Clock interface + Now func() time.Time + type CodeGenerator interface + NewCode func() (string, error) + type Config struct + DefaultIntentTTL time.Duration + DefaultLoginLinkTTL time.Duration + DefaultRedemptionMode IntentRedemptionMode + DefaultReusableMaxRedemptions int + func DefaultConfig() Config + type CreateIntentInput struct + Audience string + ExpiresAt *time.Time + Identity *Identity + MaxRedemptions int + Messenger Messenger + Metadata map[string]string + RedemptionMode IntentRedemptionMode + SubjectID string + type CreateLoginLinkInput struct + Audience string + Identity *Identity + IntentExpiresAt *time.Time + LinkExpiresAt *time.Time + MaxRedemptions int + Messenger Messenger + Metadata map[string]string + RedemptionMode IntentRedemptionMode + SubjectID string + type CreateLoginLinkOutput struct + ExpiresAt time.Time + Intent AuthIntent + LinkToken string + LoginURL string + type HMACLoginTokenCodec struct + SigningKey []byte + func (c HMACLoginTokenCodec) Decode(ctx context.Context, token string) (LoginTokenClaims, error) + func (c HMACLoginTokenCodec) Encode(ctx context.Context, claims LoginTokenClaims) (string, error) + type IDGenerator interface + NewID func() string + type Identity struct + Attributes map[string]string + BirthDate *time.Time + Messenger Messenger + MessengerUserID string + Name string + Surname string + Username string + type InMemoryIntentStore struct + func NewInMemoryIntentStore() *InMemoryIntentStore + func (s *InMemoryIntentStore) Create(ctx context.Context, intent AuthIntent) error + func (s *InMemoryIntentStore) DeleteExpired(ctx context.Context, now time.Time) error + func (s *InMemoryIntentStore) FindByCode(ctx context.Context, messenger Messenger, code string) (AuthIntent, error) + func (s *InMemoryIntentStore) RecordRedemption(ctx context.Context, intentID string, redeemedAt time.Time) error + type InMemoryLinkStore struct + func NewInMemoryLinkStore() *InMemoryLinkStore + func (s *InMemoryLinkStore) FindByIdentity(ctx context.Context, identity Identity) (AccountLink, error) + func (s *InMemoryLinkStore) Upsert(ctx context.Context, link AccountLink) error + type InMemorySessionIssuer struct + func NewInMemorySessionIssuer(ttl time.Duration, opts ...SessionIssuerOption) (*InMemorySessionIssuer, error) + func (s *InMemorySessionIssuer) Issue(ctx context.Context, appUserID string) (WebSession, error) + func (s *InMemorySessionIssuer) Validate(ctx context.Context, token string) (WebSession, error) + type IntentRedemptionMode string + const IntentOneTime + const IntentReusable + type IntentState string + const IntentActive + const IntentExpired + const IntentRevoked + type IntentStore interface + Create func(ctx context.Context, intent AuthIntent) error + DeleteExpired func(ctx context.Context, now time.Time) error + FindByCode func(ctx context.Context, messenger Messenger, code string) (AuthIntent, error) + RecordRedemption func(ctx context.Context, intentID string, redeemedAt time.Time) error + type LinkProvisioner interface + ProvisionLink func(ctx context.Context, identity Identity) (AccountLink, error) + type LinkProvisionerFunc func(ctx context.Context, identity Identity) (AccountLink, error) + func (f LinkProvisionerFunc) ProvisionLink(ctx context.Context, identity Identity) (AccountLink, error) + type LinkStore interface + FindByIdentity func(ctx context.Context, identity Identity) (AccountLink, error) + Upsert func(ctx context.Context, link AccountLink) error + type LoginLinkBuilder interface + BuildURL func(ctx context.Context, token string) (string, error) + type LoginTokenClaims struct + ExpiresAt time.Time + IntentCode string + Messenger Messenger + type LoginTokenCodec interface + Decode func(ctx context.Context, token string) (LoginTokenClaims, error) + Encode func(ctx context.Context, claims LoginTokenClaims) (string, error) + type Messenger struct + ID string + func NewMessenger(id string) Messenger + type MissingIdentityLinkMode string + const MissingIdentityLinkAutoProvision + const MissingIdentityLinkDeferred + const MissingIdentityLinkStrict + type Option func(*AuthService) error + func WithAudienceResolver(resolver AudienceResolver) Option + func WithClock(clock Clock) Option + func WithCodeGenerator(gen CodeGenerator) Option + func WithConfig(cfg Config) Option + func WithIDGenerator(gen IDGenerator) Option + func WithLinkProvisioner(provisioner LinkProvisioner) Option + func WithLoginLinkBuilder(builder LoginLinkBuilder) Option + func WithLoginTokenCodec(codec LoginTokenCodec) Option + func WithMissingIdentityLinkMode(mode MissingIdentityLinkMode) Option + func WithSignedQueryLoginLinks(baseURL string, signingKey []byte, tokenQueryParam string) Option + type QueryLoginLinkBuilder struct + BaseURL string + TokenQueryParam string + func (b QueryLoginLinkBuilder) BuildURL(ctx context.Context, token string) (string, error) + type RedeemIntentInput struct + Code string + Identity *Identity + Messenger Messenger + type RedeemLoginLinkInput struct + Identity *Identity + LinkToken string + type SecureCodeGenerator struct + NumBytes int + func (g SecureCodeGenerator) NewCode() (string, error) + type Service interface + CreateIntent func(ctx context.Context, in CreateIntentInput) (AuthIntent, error) + RedeemIntent func(ctx context.Context, in RedeemIntentInput) (WebSession, error) + type SessionIssuer interface + Issue func(ctx context.Context, appUserID string) (WebSession, error) + Validate func(ctx context.Context, token string) (WebSession, error) + type SessionIssuerOption func(*InMemorySessionIssuer) error + func WithSessionClock(clock Clock) SessionIssuerOption + func WithSessionIDGenerator(gen IDGenerator) SessionIssuerOption + func WithSessionTokenGenerator(gen CodeGenerator) SessionIssuerOption + type UUIDGenerator struct + func (UUIDGenerator) NewID() string + type WebSession struct + ExpiresAt time.Time + IssuedAt time.Time + SessionID string + SubjectID string + Token string