Documentation
¶
Index ¶
- func MaskEmail(email string) string
- type AuthHandler
- func (h *AuthHandler) ForgotPassword(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) RegisterUser(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ResendMFA(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) VerifyEmail(w http.ResponseWriter, r *http.Request)
- func (h *AuthHandler) VerifyMFA(w http.ResponseWriter, r *http.Request)
- type AuthHandlerOption
- type BlockedEmailChecker
- type CompleteSetupRequest
- type CompleteSetupResponse
- type FirstLoginHandler
- type FirstLoginRequiredResponse
- type FirstLoginStatus
- type ForgotPasswordRequest
- type LoginRequest
- type LoginResponse
- type LogoutResponse
- type MFACodeDeliverer
- type MFARequiredResponse
- type MFAResendRequest
- type MFAResendResponse
- type MFAVerifyRequest
- type Mailer
- type NotificationRecorder
- type RegisterUserRequest
- type RegisterUserResponse
- type ResendVerificationRequest
- type ResendVerificationResponse
- type ResetPasswordRequest
- type TokenIssuer
- type UserInfoRef
- type UserStore
- type VerifyEmailResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
func NewAuthHandler ¶
func NewAuthHandler( authService *authdomain.AuthService, jwtManager TokenIssuer, logger kernel.Logger, firstLoginService *authdomain.FirstLoginService, registrationService *authdomain.RegistrationService, verificationService *authdomain.VerificationService, loginService *authdomain.LoginService, mfaService *authdomain.MFAService, passwordResetService *authdomain.PasswordResetService, userRepo UserStore, failedLoginRepo authdomain.FailedLoginAttemptRepo, notificationRepo NotificationRecorder, emailService Mailer, mfaDeliverer MFACodeDeliverer, blockedEmailRepo BlockedEmailChecker, opts ...AuthHandlerOption, ) *AuthHandler
NewAuthHandler creates a new auth handler. A nil logger degrades to a discard sink so the handler is safe to construct in any context.
func (*AuthHandler) ForgotPassword ¶
func (h *AuthHandler) ForgotPassword(w http.ResponseWriter, r *http.Request)
ForgotPassword handles POST /api/auth/forgot-password
func (*AuthHandler) Login ¶
func (h *AuthHandler) Login(w http.ResponseWriter, r *http.Request)
Login handles POST /api/auth/login
func (*AuthHandler) Logout ¶
func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request)
Logout handles POST /api/auth/logout. It revokes every session for the caller by bumping the stored token version — previously issued Bearer tokens and session cookies stop validating on the next request — and clears the session cookie with matching attributes. It runs behind RequireAuth, so a missing credential never reaches it; the defensive rejection below only covers a forged context.
func (*AuthHandler) RegisterUser ¶
func (h *AuthHandler) RegisterUser(w http.ResponseWriter, r *http.Request)
RegisterUser handles POST /api/auth/register
func (*AuthHandler) ResendMFA ¶
func (h *AuthHandler) ResendMFA(w http.ResponseWriter, r *http.Request)
ResendMFA handles POST /api/auth/mfa/resend, replacing the pending challenge with a fresh code subject to the resend cooldown.
func (*AuthHandler) ResendVerificationEmail ¶
func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Request)
ResendVerificationEmail handles POST /api/auth/resend-verification
func (*AuthHandler) ResetPassword ¶
func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request)
ResetPassword handles POST /api/auth/reset-password
func (*AuthHandler) VerifyEmail ¶
func (h *AuthHandler) VerifyEmail(w http.ResponseWriter, r *http.Request)
VerifyEmail handles GET /api/auth/verify-email
func (*AuthHandler) VerifyMFA ¶
func (h *AuthHandler) VerifyMFA(w http.ResponseWriter, r *http.Request)
VerifyMFA handles POST /api/auth/mfa/verify and issues the session JWT only after the emailed code is accepted.
type AuthHandlerOption ¶
type AuthHandlerOption func(*AuthHandler)
AuthHandler handles authentication HTTP requests AuthHandlerOption customizes an AuthHandler at construction time
func WithAdminApprovalRequired ¶
func WithAdminApprovalRequired() AuthHandlerOption
WithAdminApprovalRequired configures the handler for sites where registrants must be approved by an administrator after verifying their email. A pending registrant whose email is already verified is not issued another verification link (the reply stays generic for anti-enumeration); without this option the resend endpoint always re-issues a link for pending registrants (legacy).
type BlockedEmailChecker ¶
type BlockedEmailChecker interface {
IsEmailBlocked(ctx context.Context, email string) (bool, error)
}
BlockedEmailChecker reports whether an email address is blocked from registering. The core blocked-email repository satisfies it structurally.
type CompleteSetupRequest ¶
type CompleteSetupRequest struct {
Password string `json:"password"`
Email string `json:"email"`
DatabaseType string `json:"databaseType"`
}
CompleteSetupRequest represents the request body for completing first-login setup
type CompleteSetupResponse ¶
type CompleteSetupResponse struct {
Message string `json:"message"`
Redirect string `json:"redirect"`
}
CompleteSetupResponse represents the response for completing first-login setup
type FirstLoginHandler ¶
type FirstLoginHandler struct {
// contains filtered or unexported fields
}
FirstLoginHandler handles first-login setup HTTP requests
func NewFirstLoginHandler ¶
func NewFirstLoginHandler( firstLoginService *authdomain.FirstLoginService, userRepo UserStore, policy authdomain.CredentialPolicy, logger kernel.Logger, ) *FirstLoginHandler
NewFirstLoginHandler creates a new first-login handler. A nil logger degrades to a discard sink so the handler is safe to construct in any context.
func (*FirstLoginHandler) CompleteSetup ¶
func (h *FirstLoginHandler) CompleteSetup(w http.ResponseWriter, r *http.Request)
CompleteSetup handles POST /api/auth/first-login
func (*FirstLoginHandler) GetStatus ¶
func (h *FirstLoginHandler) GetStatus(w http.ResponseWriter, r *http.Request)
GetStatus handles GET /api/auth/first-login
type FirstLoginRequiredResponse ¶
type FirstLoginRequiredResponse struct {
FirstLoginRequired bool `json:"firstLoginRequired"`
}
FirstLoginRequiredResponse tells the client to open the first-login setup page instead of completing a session. The bootstrap admin has no email address until setup finishes, so no code can be delivered yet.
type FirstLoginStatus ¶
type FirstLoginStatus struct {
FirstLoginComplete bool `json:"firstLoginComplete"`
Redirect string `json:"redirect,omitempty"`
}
FirstLoginStatus represents the first-login status response
type ForgotPasswordRequest ¶
type ForgotPasswordRequest struct {
Email string `json:"email"`
}
ForgotPasswordRequest represents the forgot password request body
type LoginRequest ¶
type LoginRequest struct {
// Username carries the login identifier: a username or an email address.
Username string `json:"username"`
Password string `json:"password"`
}
LoginRequest represents the login request body
type LoginResponse ¶
type LoginResponse struct {
User UserInfoRef `json:"user"`
}
LoginResponse represents the successful login response. The session travels in the HttpOnly cookie, never in the body.
type LogoutResponse ¶
type LogoutResponse struct {
Message string `json:"message"`
}
LogoutResponse represents the successful logout response. Sessions are revoked server-side and the session cookie is cleared.
type MFACodeDeliverer ¶
type MFACodeDeliverer interface {
DeliverMFACode(ctx context.Context, to, username, code string) error
}
MFACodeDeliverer delivers the one-time login code to the second factor channel. The composition root picks the adapter: email whenever SMTP is configured, and a log-only sink only when DEV_MODE is on and SMTP is absent.
type MFARequiredResponse ¶
type MFARequiredResponse struct {
MFARequired bool `json:"mfaRequired"`
ChallengeToken string `json:"challengeToken"`
EmailHint string `json:"emailHint"`
ExpiresIn int `json:"expiresIn"`
}
MFARequiredResponse is the first login step's reply: credentials were accepted, and the emailed code must be presented to finish signing in.
type MFAResendRequest ¶
type MFAResendRequest struct {
ChallengeToken string `json:"challengeToken"`
}
MFAResendRequest represents the resend request body.
type MFAResendResponse ¶
type MFAResendResponse struct {
Message string `json:"message"`
ChallengeToken string `json:"challengeToken"`
EmailHint string `json:"emailHint"`
ExpiresIn int `json:"expiresIn"`
}
MFAResendResponse represents the resend response body. A resend replaces the challenge, so the new token must travel back to the client.
type MFAVerifyRequest ¶
type MFAVerifyRequest struct {
ChallengeToken string `json:"challengeToken"`
Code string `json:"code"`
}
MFAVerifyRequest represents the second login step's request body.
type Mailer ¶
type Mailer interface {
SendVerificationEmail(ctx context.Context, to, username, token string) error
SendPasswordResetEmail(ctx context.Context, to, username, token string) error
SendAccountLockoutEmail(ctx context.Context, to, username string) error
SendRegistrationAttemptEmail(ctx context.Context, to, username string) error
}
Mailer sends the account emails the auth flow triggers. It carries exactly the sends the handlers perform; the core email service satisfies it structurally.
type NotificationRecorder ¶
type NotificationRecorder interface {
RecordUserRegistered(ctx context.Context, username, email string) error
RecordUserVerified(ctx context.Context, username, email string) error
}
NotificationRecorder records admin-facing notifications for auth events. It names intents, not storage types: the core adapter persists them through the notification repository.
type RegisterUserRequest ¶
type RegisterUserRequest struct {
Username string `json:"username"`
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
ConsentAccepted bool `json:"consentAccepted,omitempty"`
}
RegisterUserRequest represents the registration request body
type RegisterUserResponse ¶
type RegisterUserResponse struct {
Message string `json:"message"`
}
RegisterUserResponse is the registration response. Deliberately minimal: a duplicate username or email must be indistinguishable from success, so the body never includes the new account's ID (a conflict has none) and both outcomes share one message and status.
type ResendVerificationRequest ¶
type ResendVerificationRequest struct {
Email string `json:"email"`
}
ResendVerificationRequest represents the resend verification request body
type ResendVerificationResponse ¶
type ResendVerificationResponse struct {
Message string `json:"message"`
}
ResendVerificationResponse represents the successful resend response
type ResetPasswordRequest ¶
type ResetPasswordRequest struct {
Token string `json:"token"`
NewPassword string `json:"newPassword"`
}
ResetPasswordRequest represents the reset password request body
type TokenIssuer ¶
type TokenIssuer interface {
GenerateToken(userID, username, role string, tokenVersion int) (string, error)
// ValidateTokenExpiry validates the token and reports its expiry so the
// session cookie lifetime matches the token instead of duplicating the
// TTL.
ValidateTokenExpiry(token string) (time.Time, error)
}
TokenIssuer mints JWTs for authenticated sessions. The core JWT manager satisfies it structurally through the composition-root adapter; verification stays core-side (middleware).
type UserInfoRef ¶
type UserInfoRef struct {
ID string `json:"id"`
Username string `json:"username"`
Role string `json:"role"`
}
UserInfoRef represents user information returned in login response
type UserStore ¶
type UserStore interface {
GetUserByUsername(ctx context.Context, username string) (*userdomain.User, error)
GetUserByEmail(ctx context.Context, email string) (*userdomain.User, error)
GetUserByID(ctx context.Context, userID int) (*userdomain.User, error)
GetAdminUser(ctx context.Context) (*userdomain.User, error)
UpdateAdminPasswordAndEmail(ctx context.Context, passwordHash, email, currentPasswordHash string) error
// RevokeSessions bumps the stored token version so every previously
// issued session for the user stops validating.
RevokeSessions(ctx context.Context, userID int) error
}
UserStore is the user-repository subset the auth handlers need.
type VerifyEmailResponse ¶
type VerifyEmailResponse struct {
Message string `json:"message"`
// AwaitingApproval reports that the email address was proven but the account
// stays pending because the site requires admin approval for activation.
AwaitingApproval bool `json:"awaitingApproval"`
Redirect string `json:"redirect"`
}
VerifyEmailResponse represents the successful email verification response