Documentation
¶
Index ¶
- Constants
- Variables
- func FedProviderKey(workspaceID string) string
- func HashPassword(password string) (string, error)
- func VerifyPassword(password, phc string) bool
- type AccountConfig
- type AccountService
- func (s *AccountService) DeleteAccount(ctx context.Context, p *webx.Principal) error
- func (s *AccountService) DeleteAccountFor(ctx context.Context, actor *webx.Principal, targetUserID string) error
- func (s *AccountService) MarkVerified(ctx context.Context, targetUserID string) error
- func (s *AccountService) RequestPasswordReset(ctx context.Context, rawEmail string) error
- func (s *AccountService) ResendVerificationFor(ctx context.Context, email string) error
- func (s *AccountService) ResetPassword(ctx context.Context, rawEmail, token, newPassword string) error
- func (s *AccountService) ResetPasswordFor(ctx context.Context, targetUserID string) error
- func (s *AccountService) SendVerification(ctx context.Context, p *webx.Principal) error
- func (s *AccountService) VerifyEmail(ctx context.Context, rawEmail, token string) error
- func (s *AccountService) WithAuditor(a Auditor) *AccountService
- type Auditor
- type Challenge
- type Clock
- type EmailSender
- type FedOIDCProvider
- type FedOption
- type FedProviderRow
- type FedResolver
- type FedService
- func (s *FedService) Callback(ctx context.Context, r *http.Request, code, state string, gate SignupGateCheck) (ThirdPartyLinkResult, error)
- func (s *FedService) DeleteProvider(ctx context.Context, workspaceID string) error
- func (s *FedService) GetProvider(ctx context.Context, workspaceID string) (*FedProviderRow, bool, error)
- func (s *FedService) Start(w http.ResponseWriter, r *http.Request, slug string) error
- func (s *FedService) UpsertProvider(ctx context.Context, ...) (*FedProviderRow, error)
- func (s *FedService) WithSecureCookie(secure bool) *FedService
- type LoginResult
- type NoopEmailSender
- func (NoopEmailSender) SendEmailVerification(ctx context.Context, to, link string) error
- func (NoopEmailSender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error
- func (NoopEmailSender) SendLoginCode(ctx context.Context, to, code string) error
- func (NoopEmailSender) SendPasswordReset(ctx context.Context, to, link string) error
- type OAuthIdentity
- type OAuthProvider
- type OAuthService
- func (s *OAuthService) Callback(ctx context.Context, r *http.Request, providerName, code, state string, ...) (ThirdPartyLinkResult, error)
- func (s *OAuthService) Names() []string
- func (s *OAuthService) Start(w http.ResponseWriter, r *http.Request, providerName string) error
- func (s *OAuthService) WithSecureCookie(secure bool) *OAuthService
- type PAT
- type Repo
- type Secrets
- type SessionConfig
- type SessionInfo
- type SessionService
- func (s *SessionService) ChangePassword(ctx context.Context, p *webx.Principal, oldPassword, newPassword string) (*LoginResult, error)
- func (s *SessionService) CompleteThirdPartyLogin(ctx context.Context, userID string, jitNew bool, ipHash, userAgent string) (*LoginResult, error)
- func (s *SessionService) ConfirmPassword(ctx context.Context, ipHash string, p *webx.Principal, password string) (time.Time, error)
- func (s *SessionService) FireOnLoginFailed(ctx context.Context, email, ipHash string)
- func (s *SessionService) ListSessions(ctx context.Context, p *webx.Principal) ([]SessionInfo, error)
- func (s *SessionService) ListSessionsFor(ctx context.Context, targetUserID string) ([]SessionInfo, error)
- func (s *SessionService) LoginWithPassword(ctx context.Context, ipHash, userAgent, rawEmail, password string) (*LoginResult, error)
- func (s *SessionService) Logout(ctx context.Context, token string) error
- func (s *SessionService) Me(ctx context.Context, p *webx.Principal) (User, error)
- func (s *SessionService) Register(ctx context.Context, ipHash, userAgent, rawEmail, password, displayName string) (*LoginResult, error)
- func (s *SessionService) RevokeAllSessions(ctx context.Context, p *webx.Principal) error
- func (s *SessionService) RevokeAllSessionsFor(ctx context.Context, targetUserID string) error
- func (s *SessionService) RevokeSessionByID(ctx context.Context, p *webx.Principal, sessionID string) error
- func (s *SessionService) RevokeSessionByIDFor(ctx context.Context, targetUserID, sessionID string) error
- func (s *SessionService) SendCode(ctx context.Context, ipHash, rawEmail string) error
- func (s *SessionService) SignupBlocked(email string) bool
- func (s *SessionService) UpdateProfile(ctx context.Context, p *webx.Principal, displayName, avatarURL string) (User, error)
- func (s *SessionService) VerifyCode(ctx context.Context, ipHash, userAgent, rawEmail, code string) (*LoginResult, error)
- func (s *SessionService) WithHooks(h identity.IdentityHooks) *SessionService
- func (s *SessionService) WithSignupGate(gate SignupGate) *SessionService
- type SignupGate
- type SignupGateCheck
- type ThirdPartyLinkResult
- type TokenService
- func (s *TokenService) CreatePAT(ctx context.Context, p *webx.Principal, name string, ttl time.Duration, ...) (PAT, string, error)
- func (s *TokenService) ListPATs(ctx context.Context, p *webx.Principal) ([]PAT, error)
- func (s *TokenService) ListPATsFor(ctx context.Context, targetUserID string) ([]PAT, error)
- func (s *TokenService) RevokePAT(ctx context.Context, p *webx.Principal, patID string) error
- func (s *TokenService) RevokePATFor(ctx context.Context, targetUserID, patID string) error
- func (s *TokenService) WithPATPrefix(prefix string) *TokenService
- type User
- type WorkspaceSlugLookup
Constants ¶
View Source
const ( CodeSealKeyMissing = "E_SEAL_KEY_MISSING" CodeSealFailed = "E_SEAL_FAILED" )
View Source
const FedLoginCookie = "tk_fed_oauth"
View Source
const FedProviderPrefix = "oidc_fed:"
View Source
const FedSecretMask = "***"
View Source
const OAuthStateCookie = "tk_oauth_state"
Variables ¶
View Source
var ErrDuplicate = errors.New("duplicate")
View Source
var ErrNotFound = errors.New("not found")
Functions ¶
func FedProviderKey ¶
func HashPassword ¶
func VerifyPassword ¶
Types ¶
type AccountConfig ¶
type AccountService ¶
type AccountService struct {
// contains filtered or unexported fields
}
func NewAccountService ¶
func NewAccountService(repo Repo, mail EmailSender, cfg AccountConfig, now Clock) *AccountService
func (*AccountService) DeleteAccount ¶
func (*AccountService) DeleteAccountFor ¶
func (*AccountService) MarkVerified ¶
func (s *AccountService) MarkVerified(ctx context.Context, targetUserID string) error
func (*AccountService) RequestPasswordReset ¶
func (s *AccountService) RequestPasswordReset(ctx context.Context, rawEmail string) error
func (*AccountService) ResendVerificationFor ¶
func (s *AccountService) ResendVerificationFor(ctx context.Context, email string) error
func (*AccountService) ResetPassword ¶
func (s *AccountService) ResetPassword(ctx context.Context, rawEmail, token, newPassword string) error
func (*AccountService) ResetPasswordFor ¶
func (s *AccountService) ResetPasswordFor(ctx context.Context, targetUserID string) error
func (*AccountService) SendVerification ¶
func (*AccountService) VerifyEmail ¶
func (s *AccountService) VerifyEmail(ctx context.Context, rawEmail, token string) error
func (*AccountService) WithAuditor ¶
func (s *AccountService) WithAuditor(a Auditor) *AccountService
type EmailSender ¶
type FedOIDCProvider ¶
type FedProviderRow ¶
type FedResolver ¶
type FedResolver interface {
Resolve(ctx context.Context, issuerURL, clientID, clientSecret, scopes string) (FedOIDCProvider, error)
}
type FedService ¶
type FedService struct {
// contains filtered or unexported fields
}
func NewFedService ¶
func NewFedService(repo Repo, slugLookup WorkspaceSlugLookup, resolver FedResolver, now Clock, opts ...FedOption) *FedService
func (*FedService) Callback ¶
func (s *FedService) Callback(ctx context.Context, r *http.Request, code, state string, gate SignupGateCheck) (ThirdPartyLinkResult, error)
func (*FedService) DeleteProvider ¶
func (s *FedService) DeleteProvider(ctx context.Context, workspaceID string) error
func (*FedService) GetProvider ¶
func (s *FedService) GetProvider(ctx context.Context, workspaceID string) (*FedProviderRow, bool, error)
func (*FedService) Start ¶
func (s *FedService) Start(w http.ResponseWriter, r *http.Request, slug string) error
func (*FedService) UpsertProvider ¶
func (s *FedService) UpsertProvider(ctx context.Context, workspaceID, issuerURL, clientID, clientSecret, scopes string) (*FedProviderRow, error)
func (*FedService) WithSecureCookie ¶
func (s *FedService) WithSecureCookie(secure bool) *FedService
type LoginResult ¶
type NoopEmailSender ¶ added in v0.4.1
type NoopEmailSender struct{}
NoopEmailSender satisfies EmailSender with every send as a no-op (orkome F12): products that only use code login embed it and override exactly the sends they need, instead of hand-writing no-op stubs for SendInvite / SendPasswordReset / SendEmailVerification on every adapter.
type DevMailer struct {
app.NoopEmailSender // invites/resets/verifications silently dropped
}
func (DevMailer) SendLoginCode(ctx context.Context, to, code string) error { ... }
func (NoopEmailSender) SendEmailVerification ¶ added in v0.4.1
func (NoopEmailSender) SendEmailVerification(ctx context.Context, to, link string) error
func (NoopEmailSender) SendInvite ¶ added in v0.4.1
func (NoopEmailSender) SendInvite(ctx context.Context, to, workspaceName, invitationID string) error
func (NoopEmailSender) SendLoginCode ¶ added in v0.4.1
func (NoopEmailSender) SendLoginCode(ctx context.Context, to, code string) error
func (NoopEmailSender) SendPasswordReset ¶ added in v0.4.1
func (NoopEmailSender) SendPasswordReset(ctx context.Context, to, link string) error
type OAuthIdentity ¶
type OAuthProvider ¶
type OAuthService ¶
type OAuthService struct {
// contains filtered or unexported fields
}
func NewOAuthService ¶
func NewOAuthService(repo Repo, providers []OAuthProvider, now Clock) *OAuthService
func (*OAuthService) Callback ¶
func (s *OAuthService) Callback(ctx context.Context, r *http.Request, providerName, code, state string, gate SignupGateCheck) (ThirdPartyLinkResult, error)
func (*OAuthService) Names ¶
func (s *OAuthService) Names() []string
func (*OAuthService) Start ¶
func (s *OAuthService) Start(w http.ResponseWriter, r *http.Request, providerName string) error
func (*OAuthService) WithSecureCookie ¶
func (s *OAuthService) WithSecureCookie(secure bool) *OAuthService
type Repo ¶
type Repo interface {
UpsertUserByEmail(ctx context.Context, email string, now time.Time) (User, error)
GetUser(ctx context.Context, id string) (User, error)
GetUserByEmail(ctx context.Context, email string) (User, bool, error)
UpdateProfile(ctx context.Context, id, displayName, avatarURL string) (User, error)
CreateUserWithPassword(ctx context.Context, email, passwordHash, displayName string) (User, error)
SetPasswordHash(ctx context.Context, userID, passwordHash string, now time.Time) error
SetEmailVerified(ctx context.Context, userID string, at time.Time) error
FindOAuthAccount(ctx context.Context, provider, subject string) (userID string, ok bool, err error)
LinkOAuthAccount(ctx context.Context, provider, subject, userID, emailAtLink string, now time.Time) error
GetFedProvider(ctx context.Context, workspaceID string) (*FedProviderRow, bool, error)
UpsertFedProvider(ctx context.Context, row *FedProviderRow, now time.Time) error
DeleteFedProvider(ctx context.Context, workspaceID string) error
CreateChallenge(ctx context.Context, email, kind, secretHash string, expiresAt time.Time) error
LatestPendingChallenge(ctx context.Context, email, kind string) (*Challenge, error)
IncChallengeAttempts(ctx context.Context, id string) error
ConsumeChallenge(ctx context.Context, id string) error
CreateSession(ctx context.Context, in webx.SessionCreate) (token string, exp time.Time, err error)
VerifySession(ctx context.Context, token string, now time.Time) (*webx.Principal, error)
// ConfirmSessionPassword stamps password_confirmed_at on a live session
// (step-up): POST /auth/confirm-password → RequireRecentAuth unblocks.
ConfirmSessionPassword(ctx context.Context, sessionID string, now time.Time) error
RenewSession(ctx context.Context, token string, now time.Time) (exp time.Time, renewed bool, err error)
RevokeSession(ctx context.Context, token string) error
RevokeAllUserSessions(ctx context.Context, userID string) error
ListUserSessions(ctx context.Context, userID string) ([]SessionInfo, error)
RevokeUserSessionByID(ctx context.Context, userID, sessionID string, now time.Time) error
CreatePAT(ctx context.Context, userID, name, tokenHash, prefix string, expiresAt *time.Time, scope *webx.CredentialScope) (PAT, error)
ResolvePAT(ctx context.Context, token string, now time.Time) (*webx.Principal, error)
ListPATs(ctx context.Context, userID string) ([]PAT, error)
RevokePAT(ctx context.Context, userID, patID string, now time.Time) error
CountRecentAttempts(ctx context.Context, ipHash, identity string, since time.Time) (int, error)
RecordAttempt(ctx context.Context, ipHash, identity string, success bool, at time.Time) error
CleanupAttempts(ctx context.Context, before time.Time) error
RunInTx(ctx context.Context, fn func(ctx context.Context, tx pgx.Tx) error) error
CreateUserWithPasswordTx(ctx context.Context, tx pgx.Tx, email, passwordHash, displayName string) (User, error)
SoftDeleteUserTx(ctx context.Context, tx pgx.Tx, userID string, now time.Time) error
}
type SessionConfig ¶
type SessionInfo ¶
type SessionInfo struct {
ID string `json:"id"`
IPHash string `json:"ip_hash"`
UserAgent string `json:"user_agent"`
LastSeenAt time.Time `json:"last_seen_at"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at"`
Current bool `json:"current"`
ImpersonatedBy string `json:"impersonated_by,omitempty"`
}
type SessionService ¶
type SessionService struct {
// contains filtered or unexported fields
}
func NewSessionService ¶
func NewSessionService(repo Repo, mail EmailSender, cfg SessionConfig, sessionTTL, _ time.Duration, now Clock) *SessionService
func (*SessionService) ChangePassword ¶
func (s *SessionService) ChangePassword(ctx context.Context, p *webx.Principal, oldPassword, newPassword string) (*LoginResult, error)
func (*SessionService) CompleteThirdPartyLogin ¶
func (s *SessionService) CompleteThirdPartyLogin(ctx context.Context, userID string, jitNew bool, ipHash, userAgent string) (*LoginResult, error)
func (*SessionService) ConfirmPassword ¶ added in v0.4.0
func (s *SessionService) ConfirmPassword(ctx context.Context, ipHash string, p *webx.Principal, password string) (time.Time, error)
ConfirmPassword re-verifies the caller's password and stamps the current session (step-up). It backs the two-phase protocol of webx.RequireRecentAuth: 403 E_REAUTH_REQUIRED → confirm here → retry the original request. Failed confirmations go through the same attempt limiter as login (a hijacked session must not brute-force the password).
func (*SessionService) FireOnLoginFailed ¶
func (s *SessionService) FireOnLoginFailed(ctx context.Context, email, ipHash string)
func (*SessionService) ListSessions ¶
func (s *SessionService) ListSessions(ctx context.Context, p *webx.Principal) ([]SessionInfo, error)
func (*SessionService) ListSessionsFor ¶
func (s *SessionService) ListSessionsFor(ctx context.Context, targetUserID string) ([]SessionInfo, error)
func (*SessionService) LoginWithPassword ¶
func (s *SessionService) LoginWithPassword(ctx context.Context, ipHash, userAgent, rawEmail, password string) (*LoginResult, error)
func (*SessionService) Logout ¶
func (s *SessionService) Logout(ctx context.Context, token string) error
func (*SessionService) Register ¶
func (s *SessionService) Register(ctx context.Context, ipHash, userAgent, rawEmail, password, displayName string) (*LoginResult, error)
func (*SessionService) RevokeAllSessions ¶
func (*SessionService) RevokeAllSessionsFor ¶
func (s *SessionService) RevokeAllSessionsFor(ctx context.Context, targetUserID string) error
func (*SessionService) RevokeSessionByID ¶
func (*SessionService) RevokeSessionByIDFor ¶
func (s *SessionService) RevokeSessionByIDFor(ctx context.Context, targetUserID, sessionID string) error
func (*SessionService) SendCode ¶
func (s *SessionService) SendCode(ctx context.Context, ipHash, rawEmail string) error
func (*SessionService) SignupBlocked ¶
func (s *SessionService) SignupBlocked(email string) bool
func (*SessionService) UpdateProfile ¶
func (*SessionService) VerifyCode ¶
func (s *SessionService) VerifyCode(ctx context.Context, ipHash, userAgent, rawEmail, code string) (*LoginResult, error)
func (*SessionService) WithHooks ¶
func (s *SessionService) WithHooks(h identity.IdentityHooks) *SessionService
func (*SessionService) WithSignupGate ¶
func (s *SessionService) WithSignupGate(gate SignupGate) *SessionService
type SignupGate ¶
type SignupGateCheck ¶
type ThirdPartyLinkResult ¶
type TokenService ¶
type TokenService struct {
// contains filtered or unexported fields
}
func NewTokenService ¶
func NewTokenService(repo Repo, auditor Auditor, now Clock) *TokenService
func (*TokenService) ListPATsFor ¶
func (*TokenService) RevokePATFor ¶
func (s *TokenService) RevokePATFor(ctx context.Context, targetUserID, patID string) error
func (*TokenService) WithPATPrefix ¶
func (s *TokenService) WithPATPrefix(prefix string) *TokenService
type User ¶
type User struct {
ID string `json:"id"`
Email string `json:"email"`
DisplayName string `json:"display_name"`
AvatarURL string `json:"avatar_url,omitempty"`
Status string `json:"status"`
IsPlatformAdmin bool `json:"is_platform_admin"`
EmailVerified bool `json:"email_verified"`
PasswordHash string `json:"-"`
CreatedAt time.Time `json:"created_at"`
}
Click to show internal directories.
Click to hide internal directories.