Documentation
¶
Index ¶
- Variables
- type EmailChangeRequestResult
- type EmailChangeResult
- type MeResult
- type PasswordResetRequestResult
- type PasswordResetResult
- type Service
- func (s *Service) ChangePassword(rawToken, newPassword string) error
- func (s *Service) CreateSession(userID string) (string, error)
- func (s *Service) DeleteSession(sessionToken string) error
- func (s *Service) EmailChange(userID string, newEmail string, callbackURL *string) error
- func (s *Service) GetMe(userID string) (*MeResult, error)
- func (s *Service) GetValidAccessToken(ctx context.Context, account *models.Account, providerName string) (string, error)
- func (s *Service) RefreshOAuth2AccessToken(ctx context.Context, account *models.Account, providerName string) (string, error)
- func (s *Service) RefreshSession(sessionToken string) (string, error)
- func (s *Service) ResetPassword(email string, callbackURL *string) error
- func (s *Service) SendVerificationEmail(userID string, callbackURL *string) error
- func (s *Service) SignInWithEmailAndPassword(email string, password string, callbackURL *string) (*SignInResult, error)
- func (s *Service) SignInWithOAuth2(ctx context.Context, providerName string, code string, ...) (*SignInResult, error)
- func (s *Service) SignOut(sessionToken string) error
- func (s *Service) SignUpWithEmailAndPassword(name string, email string, password string, callbackURL *string) (*SignUpResult, error)
- func (s *Service) VerifyEmailToken(rawToken string) (*VerifyEmailResult, error)
- type SignInResult
- type SignOutResult
- type SignUpResult
- type VerifyEmailResult
Constants ¶
This section is empty.
Variables ¶
var ( // Authentication errors ErrInvalidCredentials = errors.New("invalid credentials") ErrUserNotFound = errors.New("user not found") ErrUserAlreadyExists = errors.New("user already exists") ErrInvalidPassword = errors.New("invalid password") ErrPasswordHashingFailed = errors.New("password hashing failed") // Token errors ErrTokenGenerationFailed = errors.New("token generation failed") ErrTokenExpired = errors.New("token expired") ErrInvalidToken = errors.New("invalid token") ErrNoRefreshToken = errors.New("no refresh token available") // Session errors ErrSessionNotFound = errors.New("session not found") ErrSessionCreationFailed = errors.New("session creation failed") ErrSessionDeletionFailed = errors.New("session deletion failed") ErrSessionExpired = errors.New("session expired") // Verification errors ErrVerificationNotFound = errors.New("verification token not found") ErrVerificationExpired = errors.New("verification token expired") ErrVerificationInvalid = errors.New("invalid verification token") // Account errors ErrAccountNotFound = errors.New("account not found") ErrAccountCreationFailed = errors.New("account creation failed") ErrAccountUpdateFailed = errors.New("account update failed") ErrAccountLinkingRequired = errors.New("account linking required: user exists with a different provider") // Email verification errors ErrEmailVerificationFailed = errors.New("email verification failed") // Email change errors ErrEmailAlreadyExists = errors.New("email already exists") ErrEmailChangeRequestFailed = errors.New("email change request failed") // Password reset errors ErrPasswordResetFailed = errors.New("password reset failed") ErrPasswordResetRequestFailed = errors.New("password reset request failed") // Configuration errors ErrConfigInvalid = errors.New("invalid configuration") // OAuth2 errors ErrOAuth2ProviderNotConfigured = errors.New("oauth2 provider not configured") ErrOAuth2ExchangeFailed = errors.New("oauth2 token exchange failed") ErrOAuth2UserInfoFailed = errors.New("failed to get oauth2 user info") )
Functions ¶
This section is empty.
Types ¶
type EmailChangeRequestResult ¶
type EmailChangeRequestResult struct {
Message string `json:"message"`
}
EmailChangeRequestResult represents the result of an email change request
type EmailChangeResult ¶
type EmailChangeResult struct {
Message string `json:"message"`
User *models.User `json:"user,omitempty"`
}
EmailChangeResult represents the result of confirming an email change
type PasswordResetRequestResult ¶
type PasswordResetRequestResult struct {
Message string `json:"message"`
}
PasswordResetRequestResult represents the result of a password reset request
type PasswordResetResult ¶
type PasswordResetResult struct {
Message string `json:"message"`
}
PasswordResetResult represents the result of a password reset
type Service ¶
type Service struct {
EventBus models.EventBus
UserService models.UserService
AccountService models.AccountService
SessionService models.SessionService
VerificationService models.VerificationService
TokenService models.TokenService
RateLimitService models.RateLimitService
OAuth2ProviderRegistry *providers.OAuth2ProviderRegistry
// contains filtered or unexported fields
}
Service encapsulates all authentication use-cases
func NewService ¶
func NewService( config *models.Config, eventBus models.EventBus, userService models.UserService, accountService models.AccountService, sessionService models.SessionService, verificationService models.VerificationService, tokenService models.TokenService, rateLimitService models.RateLimitService, ) *Service
NewService creates a new Auth service with all dependencies
func (*Service) ChangePassword ¶
ChangePassword completes a password reset with a verification token and new password
func (*Service) CreateSession ¶
CreateSession creates a new session for a user
func (*Service) DeleteSession ¶
DeleteSession deletes a session
func (*Service) EmailChange ¶
EmailChange initiates an email change by sending a verification email to the new address
func (*Service) GetValidAccessToken ¶ added in v1.0.4
func (s *Service) GetValidAccessToken(ctx context.Context, account *models.Account, providerName string) (string, error)
GetValidAccessToken ensures the access token is valid and refreshes it if expired or near expiry.
func (*Service) RefreshOAuth2AccessToken ¶ added in v1.0.4
func (s *Service) RefreshOAuth2AccessToken(ctx context.Context, account *models.Account, providerName string) (string, error)
RefreshOAuth2AccessToken refreshes the access token for a given account if a valid refresh token exists.
func (*Service) RefreshSession ¶
RefreshSession refreshes an existing session token
func (*Service) ResetPassword ¶
ResetPassword initiates a password reset by sending a verification email
func (*Service) SendVerificationEmail ¶
SendVerificationEmail generates a verification token and sends a verification email to the user
func (*Service) SignInWithEmailAndPassword ¶
func (s *Service) SignInWithEmailAndPassword(email string, password string, callbackURL *string) (*SignInResult, error)
SignInWithEmailAndPassword handles email/password authentication
func (*Service) SignInWithOAuth2 ¶ added in v1.0.4
func (s *Service) SignInWithOAuth2(ctx context.Context, providerName string, code string, opts ...oauth2.AuthCodeOption) (*SignInResult, error)
func (*Service) SignUpWithEmailAndPassword ¶
func (s *Service) SignUpWithEmailAndPassword(name string, email string, password string, callbackURL *string) (*SignUpResult, error)
SignUpWithEmailAndPassword handles user registration with email and password
func (*Service) VerifyEmailToken ¶
func (s *Service) VerifyEmailToken(rawToken string) (*VerifyEmailResult, error)
VerifyEmailToken handles all email verification types: verification, password reset confirmation, and email change confirmation
type SignInResult ¶
type SignInResult struct {
Token string `json:"token"`
User *models.User `json:"user"`
CSRFToken string `json:"csrf_token,omitempty"`
}
SignInResult represents the result of a sign-in operation
type SignOutResult ¶
type SignOutResult struct {
Message string `json:"message"`
}
SignOutResult represents the result of a sign-out operation
type SignUpResult ¶
type SignUpResult struct {
Token string `json:"token,omitempty"`
User *models.User `json:"user"`
CSRFToken string `json:"csrf_token,omitempty"`
}
SignUpResult represents the result of a sign-up operation
type VerifyEmailResult ¶
type VerifyEmailResult struct {
Message string `json:"message"`
User *models.User `json:"user,omitempty"`
}
VerifyEmailResult represents the result of email verification