Skip to content
A minimal, customizable Go package for Email & Mobile number verification
Go TSQL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
awsses
awssns
cmd
stores [patch] refactored main Nov 8, 2019
.editorconfig first commit Oct 13, 2019
.gitignore first commit Oct 13, 2019
.travis.yml
LICENSE
README.md
go.mod
go.sum
helper.go
helper_test.go
verifier.go
verifier_test.go [patch] updated email validator Oct 20, 2019

README.md

coverage Maintainability

Verifier v0.1.0

Verifier package lets you verify emails & phone numbers, with customization available at different components. There's a functional (if provided with valid configurations) sample app provided here.

How does it work?

Verifier generates secrets with an expiry, appropriate for emails & mobile phones. In case of emails, it generates a 256 character long random alpha-numeric string, and a 6 character long numeric string for mobile phones.

By default, it uses AWS SES for sending e-mails & AWS SNS for sending SMS/text messages.

How to customize?

You can customize the following components of verifier.

    
    // Customize the default templates
    // there should be 2 string placeholders for email body. First is the 'callback URL' and 2nd is the expiry
    verifier.DefaultEmailOTPPayload = ``
    // there should be 1 string placeholder for SMS body. It will be the secret itself
    verifier.DefaultSMSOTPPayload = ``
    // ==

    vsvc, err := verifier.NewCustom(&Config{}, nil,nil,nil)
	if err != nil {
		log.Println(err)
		return
    }
    
    // Service provider for sending emails
    err := v.CustomEmailHandler(email)
	if err != nil {
        log.Println(err)
		return
    }
    // ==

    // Service provider for sending messages to mobile
	err = v.CustomMobileHandler(mobile)
	if err != nil {
        log.Println(err)
		return err
    }
    // ==
    
    // Persistent store used by verifier for storing secrets and all the requests
	err = v.CustomStore(verStore)
	if err != nil {
        log.Println(err)
		return
    }
    // ==

    // Using custom email & text message body
    verreq, err := vsvc.NewRequest(verifier.CommTypeEmail, recipient)
    if err != nil {
        log.Println(err)
        return
    }

    // callbackURL can be used inside the custom email body
    callbackURL, err := verifier.EmailCallbackURL("https://example.com", verreq.Recipient, verreq.Secret)
    if err != nil {
        log.Println(err)
        return
    }

    err = vsvc.NewEmailWithReq(verreq, "subject", "body")
    if err != nil {
        log.Println(err)
        return
    }

    err = vsvc.NewMobileWithReq(verreq, fmt.Sprintf("%s is your OTP", verreq.Secret))
    if err != nil {
        log.Println(err)
        return
    }
    // ==

TODO

  1. Unit tests
  2. Setup a web service, which can be independently run, and consumed via APIs
You can’t perform that action at this time.