Documentation
¶
Index ¶
- Variables
- type AuthResponse
- type ChangePasswordRequest
- type GoogleOAuthCallbackRequest
- type GoogleOAuthURLRequest
- type LoginRequest
- type RefreshTokenRequest
- type RegisterRequest
- type RequestPasswordResetRequest
- type ResetPasswordRequest
- type Service
- func (s *Service) ChangePassword(ctx context.Context, userID string, req ChangePasswordRequest) error
- func (s *Service) GetGoogleOAuthAccounts(ctx context.Context, userID string) ([]*models.OAuthAccount, error)
- func (s *Service) GetGoogleOAuthURL(req GoogleOAuthURLRequest) (string, error)
- func (s *Service) GetUserByID(ctx context.Context, userID string) (*models.User, error)
- func (s *Service) GetUserPermissions(ctx context.Context, userID string) ([]*models.Permission, error)
- func (s *Service) HandleGoogleOAuthCallback(ctx context.Context, req GoogleOAuthCallbackRequest) (*AuthResponse, error)
- func (s *Service) HasPermission(ctx context.Context, userID, permissionName string) (bool, error)
- func (s *Service) HasRole(ctx context.Context, userID, roleName string) (bool, error)
- func (s *Service) Login(ctx context.Context, req LoginRequest) (*AuthResponse, error)
- func (s *Service) Logout(ctx context.Context, userID string) error
- func (s *Service) RefreshAccessToken(ctx context.Context, refreshTokenString string) (*AuthResponse, error)
- func (s *Service) Register(ctx context.Context, req RegisterRequest) (*AuthResponse, error)
- func (s *Service) RequestPasswordReset(ctx context.Context, email string) (string, error)
- func (s *Service) ResendVerificationEmail(ctx context.Context, userID string) (string, error)
- func (s *Service) ResetPassword(ctx context.Context, req ResetPasswordRequest) error
- func (s *Service) UnlinkGoogleOAuth(ctx context.Context, userID string, accountID string) error
- func (s *Service) ValidateToken(tokenString string) (*tokens.Claims, error)
- func (s *Service) VerifyEmail(ctx context.Context, token string) error
- type VerifyEmailRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCredentials is returned when credentials are invalid ErrInvalidCredentials = errors.New("invalid credentials") // ErrUserNotFound is returned when a user is not found ErrUserNotFound = errors.New("user not found") // ErrUserInactive is returned when a user account is inactive ErrUserInactive = errors.New("user account is inactive") // ErrEmailAlreadyExists is returned when an email is already registered ErrEmailAlreadyExists = errors.New("email already exists") // ErrInvalidRefreshToken is returned when a refresh token is invalid ErrInvalidRefreshToken = errors.New("invalid refresh token") // ErrPermissionDenied is returned when a user lacks required permissions ErrPermissionDenied = errors.New("permission denied") )
Functions ¶
This section is empty.
Types ¶
type AuthResponse ¶
type AuthResponse struct {
User *models.User
AccessToken string
RefreshToken string
ExpiresAt time.Time
}
AuthResponse represents an authentication response
type ChangePasswordRequest ¶
type ChangePasswordRequest struct {
OldPassword string `json:"old_password"`
NewPassword string `json:"new_password"`
}
ChangePasswordRequest represents a password change request
type GoogleOAuthCallbackRequest ¶
GoogleOAuthCallbackRequest contains parameters from OAuth callback
func ParseGoogleOAuthCallback ¶
func ParseGoogleOAuthCallback(callbackURL string) (*GoogleOAuthCallbackRequest, error)
ParseGoogleOAuthCallback parses the OAuth callback parameters from URL
func ParseGoogleOAuthCallbackFromForm ¶
func ParseGoogleOAuthCallbackFromForm(form url.Values) (*GoogleOAuthCallbackRequest, error)
ParseGoogleOAuthCallbackFromForm parses OAuth callback from form data
type GoogleOAuthURLRequest ¶
type GoogleOAuthURLRequest struct {
State string // CSRF protection token
}
GoogleOAuthURLRequest contains parameters for generating OAuth URL
type LoginRequest ¶
LoginRequest represents a user login request
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
RefreshToken string `json:"refresh_token"`
}
RefreshTokenRequest represents a token refresh request
type RegisterRequest ¶
type RegisterRequest struct {
Email string `json:"email"`
Password string `json:"password"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
RegisterRequest represents a user registration request
type RequestPasswordResetRequest ¶
type RequestPasswordResetRequest struct {
Email string `json:"email"`
}
RequestPasswordResetRequest represents a password reset request
type ResetPasswordRequest ¶
type ResetPasswordRequest struct {
Token string `json:"token"`
NewPassword string `json:"new_password"`
}
ResetPasswordRequest represents a password reset with token
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides authentication and authorization functionality
func NewService ¶
NewService creates a new authentication service
func (*Service) ChangePassword ¶
func (s *Service) ChangePassword(ctx context.Context, userID string, req ChangePasswordRequest) error
ChangePassword changes a user's password
func (*Service) GetGoogleOAuthAccounts ¶
func (s *Service) GetGoogleOAuthAccounts(ctx context.Context, userID string) ([]*models.OAuthAccount, error)
GetGoogleOAuthAccounts retrieves all Google OAuth accounts for a user
func (*Service) GetGoogleOAuthURL ¶
func (s *Service) GetGoogleOAuthURL(req GoogleOAuthURLRequest) (string, error)
GetGoogleOAuthURL generates the Google OAuth authorization URL
func (*Service) GetUserByID ¶
GetUserByID retrieves a user by their ID
func (*Service) GetUserPermissions ¶
func (s *Service) GetUserPermissions(ctx context.Context, userID string) ([]*models.Permission, error)
GetUserPermissions retrieves all permissions for a user
func (*Service) HandleGoogleOAuthCallback ¶
func (s *Service) HandleGoogleOAuthCallback(ctx context.Context, req GoogleOAuthCallbackRequest) (*AuthResponse, error)
HandleGoogleOAuthCallback handles the OAuth callback and creates/logs in user
func (*Service) HasPermission ¶
HasPermission checks if a user has a specific permission
func (*Service) Login ¶
func (s *Service) Login(ctx context.Context, req LoginRequest) (*AuthResponse, error)
Login authenticates a user with email and password
func (*Service) RefreshAccessToken ¶
func (s *Service) RefreshAccessToken(ctx context.Context, refreshTokenString string) (*AuthResponse, error)
RefreshAccessToken generates a new access token using a refresh token
func (*Service) Register ¶
func (s *Service) Register(ctx context.Context, req RegisterRequest) (*AuthResponse, error)
Register registers a new user
func (*Service) RequestPasswordReset ¶
RequestPasswordReset creates a password reset token
func (*Service) ResendVerificationEmail ¶
ResendVerificationEmail creates a new verification token and sends email
func (*Service) ResetPassword ¶
func (s *Service) ResetPassword(ctx context.Context, req ResetPasswordRequest) error
ResetPassword resets a user's password using a reset token
func (*Service) UnlinkGoogleOAuth ¶
UnlinkGoogleOAuth unlinks a Google OAuth account from a user
func (*Service) ValidateToken ¶
ValidateToken validates an access token and returns the claims
type VerifyEmailRequest ¶
type VerifyEmailRequest struct {
Token string `json:"token"`
}
VerifyEmailRequest represents an email verification request