otp

package
v0.0.0-...-2b8ec9a Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	WhatsappCodeDuration = duration.UserInteraction
)

Variables

View Source
var (
	TemplateMessageVerificationSMSTXT    = template.RegisterPlainText("messages/verification_sms.txt")
	TemplateMessageVerificationEmailTXT  = template.RegisterPlainText("messages/verification_email.txt")
	TemplateMessageVerificationEmailHTML = template.RegisterHTML("messages/verification_email.html")

	TemplateMessageSetupPrimaryOOBSMSTXT    = template.RegisterPlainText("messages/setup_primary_oob_sms.txt")
	TemplateMessageSetupPrimaryOOBEmailTXT  = template.RegisterPlainText("messages/setup_primary_oob_email.txt")
	TemplateMessageSetupPrimaryOOBEmailHTML = template.RegisterHTML("messages/setup_primary_oob_email.html")

	TemplateMessageSetupSecondaryOOBSMSTXT    = template.RegisterPlainText("messages/setup_secondary_oob_sms.txt")
	TemplateMessageSetupSecondaryOOBEmailTXT  = template.RegisterPlainText("messages/setup_secondary_oob_email.txt")
	TemplateMessageSetupSecondaryOOBEmailHTML = template.RegisterHTML("messages/setup_secondary_oob_email.txt")

	TemplateMessageAuthenticatePrimaryOOBSMSTXT    = template.RegisterPlainText("messages/authenticate_primary_oob_sms.txt")
	TemplateMessageAuthenticatePrimaryOOBEmailTXT  = template.RegisterPlainText("messages/authenticate_primary_oob_email.txt")
	TemplateMessageAuthenticatePrimaryOOBEmailHTML = template.RegisterHTML("messages/authenticate_primary_oob_email.html")

	TemplateMessageAuthenticateSecondaryOOBSMSTXT    = template.RegisterPlainText("messages/authenticate_secondary_oob_sms.txt")
	TemplateMessageAuthenticateSecondaryOOBEmailTXT  = template.RegisterPlainText("messages/authenticate_secondary_oob_email.txt")
	TemplateMessageAuthenticateSecondaryOOBEmailHTML = template.RegisterHTML("messages/authenticate_secondary_oob_email.html")
)
View Source
var ErrCodeNotFound = InvalidOTPCode.NewWithCause("otp code is expired or invalid", apierrors.StringCause("CodeNotFound"))
View Source
var ErrInputRequired = InvalidOTPCode.NewWithCause("input not yet received", apierrors.StringCause("InputRequired"))
View Source
var ErrInvalidCode = InvalidOTPCode.NewWithCause("invalid otp code", apierrors.StringCause("InvalidOTPCode"))
View Source
var InvalidOTPCode = apierrors.Forbidden.WithReason("InvalidOTPCode")

Functions

This section is empty.

Types

type Code

type Code struct {
	Target   string    `json:"target"`
	Code     string    `json:"code"`
	ExpireAt time.Time `json:"expire_at"`

	UserInputtedCode string `json:"user_inputted_code,omitempty"`
	AppID            string `json:"app_id,omitempty"`
	WebSessionID     string `json:"web_session_id,omitempty"`
}

type CodeSendResult

type CodeSendResult struct {
	Target     string
	Channel    string
	CodeLength int
}

type CodeStore

type CodeStore interface {
	Create(target string, code *Code) error
	Get(target string) (*Code, error)
	Update(target string, code *Code) error
	Delete(target string) error
}

type EndpointsProvider

type EndpointsProvider interface {
	BaseURL() *url.URL
}

type EventService

type EventService interface {
	DispatchEvent(payload event.Payload) error
}

type HardSMSBucketer

type HardSMSBucketer interface {
	Bucket() ratelimit.Bucket
}

type Logger

type Logger struct{ *log.Logger }

func NewLogger

func NewLogger(lf *log.Factory) Logger

type MessageSender

type MessageSender struct {
	Translation TranslationService
	Endpoints   EndpointsProvider
	TaskQueue   task.Queue
	Events      EventService

	RateLimiter     RateLimiter
	HardSMSBucketer HardSMSBucketer
}

func (*MessageSender) SendEmail

func (s *MessageSender) SendEmail(email string, opts SendOptions) error

func (*MessageSender) SendSMS

func (s *MessageSender) SendSMS(phone string, opts SendOptions) (err error)

type MessageTemplateContext

type MessageTemplateContext struct {
	Email string
	Phone string
	Code  string
	URL   string
	Host  string
}

type MessageType

type MessageType string
const (
	MessageTypeVerification             MessageType = "verification"
	MessageTypeSetupPrimaryOOB          MessageType = "setup-primary-oob"
	MessageTypeSetupSecondaryOOB        MessageType = "setup-secondary-oob"
	MessageTypeAuthenticatePrimaryOOB   MessageType = "authenticate-primary-oob"
	MessageTypeAuthenticateSecondaryOOB MessageType = "authenticate-secondary-oob"
)

type RateLimiter

type RateLimiter interface {
	TakeToken(bucket ratelimit.Bucket) error
}

type SendOptions

type SendOptions struct {
	OTP         string
	URL         string
	MessageType MessageType
}

type Service

type Service struct {
	Clock clock.Clock

	CodeStore CodeStore
	Logger    Logger
}

func (*Service) GenerateCode

func (s *Service) GenerateCode(target string) (*Code, error)

func (*Service) GenerateWhatsappCode

func (s *Service) GenerateWhatsappCode(target string, appID string, webSessionID string) (*Code, error)

func (*Service) SetUserInputtedCode

func (s *Service) SetUserInputtedCode(target string, userInputtedCode string) (*Code, error)

func (*Service) VerifyCode

func (s *Service) VerifyCode(target string, code string) error

func (*Service) VerifyWhatsappCode

func (s *Service) VerifyWhatsappCode(target string, consume bool) error

type StoreRedis

type StoreRedis struct {
	Redis *appredis.Handle
	AppID config.AppID
	Clock clock.Clock
}

func (*StoreRedis) Create

func (s *StoreRedis) Create(target string, code *Code) error

func (*StoreRedis) Delete

func (s *StoreRedis) Delete(target string) error

func (*StoreRedis) Get

func (s *StoreRedis) Get(target string) (*Code, error)

func (*StoreRedis) Update

func (s *StoreRedis) Update(target string, code *Code) error

type TranslationService

type TranslationService interface {
	EmailMessageData(msg *translation.MessageSpec, args interface{}) (*translation.EmailMessageData, error)
	SMSMessageData(msg *translation.MessageSpec, args interface{}) (*translation.SMSMessageData, error)
}

Jump to

Keyboard shortcuts

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