auth

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse = responses.AuthResponse

AuthResponse represents an authentication response

type Config

type Config struct {
	RequireEmailVerification bool `json:"requireEmailVerification"`
}

Config represents authentication configuration

type HookExecutor added in v0.0.3

type HookExecutor interface {
	ExecuteBeforeSignUp(ctx context.Context, req *SignUpRequest) error
	ExecuteAfterSignUp(ctx context.Context, response *responses.AuthResponse) error
	ExecuteBeforeSignIn(ctx context.Context, req *SignInRequest) error
	ExecuteAfterSignIn(ctx context.Context, response *responses.AuthResponse) error
	ExecuteBeforeSignOut(ctx context.Context, token string) error
	ExecuteAfterSignOut(ctx context.Context, token string) error
}

HookExecutor defines the interface for executing auth-related hooks This interface allows the auth service to execute hooks without importing the hooks package, avoiding circular dependencies (hooks package imports auth for request types)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides authentication operations

func NewService

func NewService(users user.ServiceInterface, session session.ServiceInterface, cfg Config, hookExecutor HookExecutor) *Service

NewService creates a new auth service

func (*Service) CheckCredentials

func (s *Service) CheckCredentials(ctx context.Context, email, password string) (*user.User, error)

CheckCredentials validates a user's credentials and returns the user without creating a session

func (*Service) CreateSessionForUser

func (s *Service) CreateSessionForUser(ctx context.Context, u *user.User, remember bool, ip, ua string) (*responses.AuthResponse, error)

CreateSessionForUser creates a session for a given user and returns auth response This is typically used after credentials are already validated (e.g., after 2FA verification)

func (*Service) GetSession

func (s *Service) GetSession(ctx context.Context, token string) (*responses.AuthResponse, error)

GetSession validates and returns session details

func (*Service) RefreshSession added in v0.0.3

func (s *Service) RefreshSession(ctx context.Context, refreshToken string) (*responses.RefreshSessionResponse, error)

RefreshSession refreshes an access token using a refresh token

func (*Service) SignIn

func (s *Service) SignIn(ctx context.Context, req *SignInRequest) (*responses.AuthResponse, error)

SignIn authenticates a user and returns a session

func (*Service) SignOut

func (s *Service) SignOut(ctx context.Context, req *SignOutRequest) error

SignOut revokes a session

func (*Service) SignUp

func (s *Service) SignUp(ctx context.Context, req *SignUpRequest) (*responses.AuthResponse, error)

SignUp registers a new user and returns a session

func (*Service) UpdateUser

func (s *Service) UpdateUser(ctx context.Context, userID xid.ID, req *user.UpdateUserRequest) (*user.User, error)

UpdateUser updates the current user's fields via user service

type ServiceInterface

type ServiceInterface interface {
	SignUp(ctx context.Context, req *SignUpRequest) (*responses.AuthResponse, error)
	SignIn(ctx context.Context, req *SignInRequest) (*responses.AuthResponse, error)
	SignOut(ctx context.Context, req *SignOutRequest) error
	CheckCredentials(ctx context.Context, email, password string) (*user.User, error)
	CreateSessionForUser(ctx context.Context, u *user.User, remember bool, ipAddress, userAgent string) (*responses.AuthResponse, error)
	GetSession(ctx context.Context, token string) (*responses.AuthResponse, error)
	UpdateUser(ctx context.Context, id xid.ID, req *user.UpdateUserRequest) (*user.User, error)
	RefreshSession(ctx context.Context, refreshToken string) (*responses.RefreshSessionResponse, error)
}

ServiceInterface defines the contract for auth service operations This allows plugins to decorate the service with additional behavior

type SignInRequest

type SignInRequest struct {
	Email      string `json:"email" validate:"required,email"`
	Password   string `json:"password" validate:"required,min=8"`
	RememberMe bool   `json:"rememberMe,omitempty"`
	// Optional alternative naming per docs
	IPAddress string `json:"ipAddress,omitempty"`
	UserAgent string `json:"userAgent,omitempty"`
}

SignInRequest represents a signin request

type SignOutRequest

type SignOutRequest struct {
	Token string `json:"token" validate:"required"`
}

SignOutRequest represents a signout request

type SignUpRequest

type SignUpRequest struct {
	Email      string `json:"email" validate:"required,email"`
	Password   string `json:"password" validate:"required,min=8"`
	Name       string `json:"name" validate:"required"`
	RememberMe bool   `json:"rememberMe,omitempty"`
	IPAddress  string `json:"ipAddress,omitempty"`
	UserAgent  string `json:"userAgent,omitempty"`
}

SignUpRequest represents a signup request

Jump to

Keyboard shortcuts

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