auth

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type GoogleOAuthCallbackRequest struct {
	Code  string
	State string
}

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

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

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

func NewService(cfg *config.Config, store store.Store) (*Service, error)

NewService creates a new authentication service

func (*Service) AssignRole added in v0.0.3

func (s *Service) AssignRole(ctx context.Context, userID, roleName string) error

AssignRole assigns a role to a user by role name

func (*Service) AssignRoleByID added in v0.0.3

func (s *Service) AssignRoleByID(ctx context.Context, userID, roleID string) error

AssignRoleByID assigns a role to a user by role ID

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

func (s *Service) GetUserByID(ctx context.Context, userID string) (*models.User, error)

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) GetUserRoles added in v0.0.3

func (s *Service) GetUserRoles(ctx context.Context, userID string) ([]*models.Role, error)

GetUserRoles retrieves all roles 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) HasAllPermissions added in v0.0.3

func (s *Service) HasAllPermissions(ctx context.Context, userID string, permissionNames []string) (bool, error)

HasAllPermissions checks if a user has all of the specified permissions

func (*Service) HasAllRoles added in v0.0.3

func (s *Service) HasAllRoles(ctx context.Context, userID string, roleNames []string) (bool, error)

HasAllRoles checks if a user has all of the specified roles

func (*Service) HasAnyPermission added in v0.0.3

func (s *Service) HasAnyPermission(ctx context.Context, userID string, permissionNames []string) (bool, error)

HasAnyPermission checks if a user has any of the specified permissions

func (*Service) HasAnyRole added in v0.0.3

func (s *Service) HasAnyRole(ctx context.Context, userID string, roleNames []string) (bool, error)

HasAnyRole checks if a user has any of the specified roles

func (*Service) HasPermission

func (s *Service) HasPermission(ctx context.Context, userID, permissionName string) (bool, error)

HasPermission checks if a user has a specific permission

func (*Service) HasRole

func (s *Service) HasRole(ctx context.Context, userID, roleName string) (bool, error)

HasRole checks if a user has a specific role

func (*Service) Login

func (s *Service) Login(ctx context.Context, req LoginRequest) (*AuthResponse, error)

Login authenticates a user with email and password

func (*Service) Logout

func (s *Service) Logout(ctx context.Context, userID string) error

Logout revokes all refresh tokens for a user

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) RemoveRole added in v0.0.3

func (s *Service) RemoveRole(ctx context.Context, userID, roleName string) error

RemoveRole removes a role from a user by role name

func (*Service) RemoveRoleByID added in v0.0.3

func (s *Service) RemoveRoleByID(ctx context.Context, userID, roleID string) error

RemoveRoleByID removes a role from a user by role ID

func (*Service) RequestPasswordReset

func (s *Service) RequestPasswordReset(ctx context.Context, email string) (string, error)

RequestPasswordReset creates a password reset token

func (*Service) ResendVerificationEmail

func (s *Service) ResendVerificationEmail(ctx context.Context, userID string) (string, error)

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

func (s *Service) UnlinkGoogleOAuth(ctx context.Context, userID string, accountID string) error

UnlinkGoogleOAuth unlinks a Google OAuth account from a user

func (*Service) ValidateToken

func (s *Service) ValidateToken(tokenString string) (*tokens.Claims, error)

ValidateToken validates an access token and returns the claims

func (*Service) VerifyEmail

func (s *Service) VerifyEmail(ctx context.Context, token string) error

VerifyEmail verifies a user's email using a verification token

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Token string `json:"token"`
}

VerifyEmailRequest represents an email verification request

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL