emailotp

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// OTPLength is the length of the OTP code
	OTPLength int `json:"otpLength"`
	// ExpiryMinutes is the OTP expiry time in minutes
	ExpiryMinutes int `json:"expiryMinutes"`
	// MaxAttempts is the maximum verification attempts
	MaxAttempts int `json:"maxAttempts"`
	// RateLimitPerHour is the max OTP requests per hour
	RateLimitPerHour int `json:"rateLimitPerHour"`
	// AllowImplicitSignup allows creating users if they don't exist
	AllowImplicitSignup bool `json:"allowImplicitSignup"`
	// DevExposeOTP exposes the OTP in dev mode (for testing)
	DevExposeOTP bool `json:"devExposeOTP"`
}

Config holds the email OTP plugin configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default email OTP plugin configuration

type ErrorResponse

type ErrorResponse = responses.ErrorResponse

Response types - use shared responses from core

type Handler

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

func NewHandler

func NewHandler(s *Service, rls *rl.Service, authInst core.Authsome) *Handler

func (*Handler) Send

func (h *Handler) Send(c forge.Context) error

Send handles sending of OTP to email

func (*Handler) Verify

func (h *Handler) Verify(c forge.Context) error

Verify checks the OTP and creates a session on success

type Plugin

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

Plugin implements the plugins.Plugin interface for Email OTP

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new email OTP plugin instance with optional configuration

func (*Plugin) ID

func (p *Plugin) ID() string

func (*Plugin) Init

func (p *Plugin) Init(authInst core.Authsome) error

func (*Plugin) Migrate

func (p *Plugin) Migrate() error

func (*Plugin) RegisterHooks

func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the email OTP plugin

func WithAllowImplicitSignup

func WithAllowImplicitSignup(allow bool) PluginOption

WithAllowImplicitSignup sets whether implicit signup is allowed

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithExpiryMinutes

func WithExpiryMinutes(minutes int) PluginOption

WithExpiryMinutes sets the OTP expiry time

func WithMaxAttempts

func WithMaxAttempts(max int) PluginOption

WithMaxAttempts sets the maximum verification attempts

func WithOTPLength

func WithOTPLength(length int) PluginOption

WithOTPLength sets the OTP code length

func WithRateLimitPerHour

func WithRateLimitPerHour(limit int) PluginOption

WithRateLimitPerHour sets the rate limit per hour

type SendRequest

type SendRequest struct {
	Email string `json:"email" validate:"required,email" example:"user@example.com"`
}

Request types

type SendResponse

type SendResponse struct {
	Status string `json:"status" example:"sent"`
	DevOTP string `json:"dev_otp,omitempty" example:"123456"`
}

Plugin-specific response

type Service

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

Service implements email OTP flow

func NewService

func NewService(
	r *repo.EmailOTPRepository,
	userSvc user.ServiceInterface,
	sessionSvc session.ServiceInterface,
	auditSvc *audit.Service,
	notifAdapter *notificationPlugin.Adapter,
	cfg Config,
	logger forge.Logger,
) *Service

func (*Service) SendOTP

func (s *Service) SendOTP(ctx context.Context, appID xid.ID, email, ip, ua string) (string, error)

func (*Service) VerifyOTP

func (s *Service) VerifyOTP(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, email, otp string, remember bool, ip, ua string) (*responses.AuthResponse, error)

type VerifyRequest

type VerifyRequest struct {
	Email    string `json:"email" validate:"required,email" example:"user@example.com"`
	OTP      string `json:"otp" validate:"required" example:"123456"`
	Remember bool   `json:"remember" example:"false"`
}

type VerifyResponse

type VerifyResponse = responses.VerifyResponse

Jump to

Keyboard shortcuts

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