Documentation ¶
Overview ¶
Package verifier is used for validation & verification of email, sms etc.
Index ¶
- Constants
- Variables
- func EmailCallbackURL(baseurl, email, secret string) (string, error)
- type CommStatus
- type Config
- type Verification
- type Verifier
- func (ver *Verifier) CustomEmailHandler(email emailService) error
- func (ver *Verifier) CustomMobileHandler(mobile mobileService) error
- func (ver *Verifier) CustomStore(verStore store) error
- func (ver *Verifier) NewEmail(recipient, subject string) error
- func (ver *Verifier) NewEmailWithReq(verreq *Verification, subject, body string) error
- func (ver *Verifier) NewMobile(recipient string) error
- func (ver *Verifier) NewMobileWithReq(verreq *Verification, body string) error
- func (ver *Verifier) NewRequest(ctype commType, recipient string) (*Verification, error)
- func (ver *Verifier) VerifyEmailSecret(recipient, secret string) error
- func (ver *Verifier) VerifyMobileSecret(recipient, secret string) error
Constants ¶
const ( // CommTypeMobile communication type mobile CommTypeMobile = commType("mobile") // CommTypeEmail communication type email CommTypeEmail = commType("email") // VerStatusPending verification status pending VerStatusPending = verificationStatus("pending") // VerStatusExpired verification status expired VerStatusExpired = verificationStatus("expired") // VerStatusVerified verification status verified VerStatusVerified = verificationStatus("verified") // VerStatusRejected verification status rejected VerStatusRejected = verificationStatus("rejected") // VerStatusExceededAttempts verification status when attempts are exceeded VerStatusExceededAttempts = verificationStatus("exceeded-attempts") )
Variables ¶
var ( // DefaultEmailOTPPayload is the default email body used DefaultEmailOTPPayload = `` /* 582-byte string literal not displayed */ // DefaultSMSOTPPayload is the default text message body DefaultSMSOTPPayload = "%s is the OTP to verify your mobile number. It is valid only for %s." )
var ( // ErrMaximumAttemptsExceeded is the error returned when maximum verification attempts have exceeded ErrMaximumAttemptsExceeded = errors.New("maximum attempts exceeded") // ErrSecretExpired is the error returned when the verification secret has expired ErrSecretExpired = errors.New("verification secret expired") // ErrInvalidSecret is the error returned upon receiving invalid secret ErrInvalidSecret = errors.New("invalid verification secret") // ErrInvalidMobileNumber is the error returned upon receiving invalid mobile number ErrInvalidMobileNumber = errors.New("invalid mobile number provided") // ErrInvalidEmail is the error returned upon receiving invalid email address ErrInvalidEmail = errors.New("invalid email address provided") // ErrEmptyEmailBody is the error returned when using custom email body and it's empty ErrEmptyEmailBody = errors.New("empty email body") // ErrEmptyMobileMessageBody is the error returned when using custom mobile message body and it's empty ErrEmptyMobileMessageBody = errors.New("empty mobile message body") )
Functions ¶
func EmailCallbackURL ¶
EmailCallbackURL adds the relevant query string parameters to the email callback URL
Types ¶
type CommStatus ¶
type CommStatus struct { Status string `json:"status,omitempty"` Data map[string]interface{} `json:"data,omitempty"` }
CommStatus stores the status of the communication sent
type Config ¶
type Config struct { // MailCfg is used to configure AWS SES handler MailCfg *awsses.Config `json:"mailCfg,omitempty"` // MobileCfg is used to configure AWS SNS handler MobileCfg *awssns.Config `json:"mobileCfg,omitempty"` // MaxVerifyAttempts is used to set the maximum number of times verification attemts can be made MaxVerifyAttempts int `json:"maxVerifyAttempts,omitempty"` // EmailOTPExpiry is used to define the expiry of a secret generated to verify email EmailOTPExpiry time.Duration `json:"emailOTPExpiry,omitempty"` // MobileOTPExpiry is used to define the expiry of a secret generated to verify mobile phone number MobileOTPExpiry time.Duration `json:"mobileOTPExpiry,omitempty"` // EmailCallbackURL is used to generate the callback link which is sent in the verification email /* Two query string attributes are added to the callback URL while sending the verification link. 1) 'email' - The email address to which verification mail was sent 2) 'secret' - The secret generated for the email, this is required while verification */ EmailCallbackURL string `json:"emailCallbackURL,omitempty"` // DefaultFromEmail is used to set the "from" email while sending verification emails DefaultFromEmail string `json:"defaultFromEmail,omitempty"` // DefaultEmailSub is the email subject set while sending verification emails /* If not set, a hardcoded string "Email verification request" is set as the subject. The default subject is used if no subject is sent while calling the Send function */ DefaultEmailSub string `json:"defaultEmailSub,omitempty"` }
Config has all the configurations required for verifier package to function
type Verification ¶
type Verification struct { ID string `json:"id,omitempty"` Type commType `json:"type,omitempty"` Sender string `json:"sender,omitempty"` Recipient string `json:"recipient,omitempty"` Data map[string]string `json:"data,omitempty"` Secret string `json:"secret,omitempty"` SecretExpiry *time.Time `json:"secretExpiry,omitempty"` // Attempts has the number of times verification has been attempted Attempts int `json:"attempts,omitempty"` // CommStatus is the communication status, and is maintained as a list to later store // statuses of retries CommStatus []CommStatus `json:"commStatus,omitempty"` Status verificationStatus `json:"status,omitempty"` CreatedAt *time.Time `json:"createdAt,omitempty"` UpdatedAt *time.Time `json:"updatedAt,omitempty"` }
Verification struct holds all data related to a single verification request
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier struct exposes all services provided by verify package
func NewCustom ¶
func NewCustom(cfg *Config, verStore store, email emailService, mobile mobileService) (*Verifier, error)
NewCustom lets you customize various components
func (*Verifier) CustomEmailHandler ¶
CustomEmailHandler is used to set a custom email sending service
func (*Verifier) CustomMobileHandler ¶
CustomMobileHandler is used to set a custom mobile message sending service
func (*Verifier) CustomStore ¶
CustomStore is used to set a custom persistent store
func (*Verifier) NewEmailWithReq ¶
func (ver *Verifier) NewEmailWithReq(verreq *Verification, subject, body string) error
NewEmailWithReq is used to send a mail with a custom verification request
func (*Verifier) NewMobile ¶
NewMobile creates a new request for mobile number verification with default setting
func (*Verifier) NewMobileWithReq ¶
func (ver *Verifier) NewMobileWithReq(verreq *Verification, body string) error
NewMobileWithReq creates a new request for mobile number verification
func (*Verifier) NewRequest ¶
func (ver *Verifier) NewRequest(ctype commType, recipient string) (*Verification, error)
NewRequest is used to create a new verification request
func (*Verifier) VerifyEmailSecret ¶
VerifyEmailSecret validates an email and its verification secret
func (*Verifier) VerifyMobileSecret ¶
VerifyMobileSecret validates a mobile number and its verification secret (OTP)