Git Product home page Git Product logo

go-sms-verification-twilio's Introduction

Go OTP Verification using Twilio

Project Summary:

This project demonstrates how to implement OTP (One-Time Password) verification using the Twilio API in Go. Users receive an OTP to their phone number, which they can then use to authenticate themselves with your application.

Key Features:

  • Secure and reliable OTP verification via Twilio's trusted service
  • Clean and well-structured Go code for maintainability
  • User-friendly API endpoints for sending and verifying OTPs
  • Detailed examples and instructions for easy setup and usage

Setup:

  1. Clone the Repository:

    git clone https://github.com/jaybaba8085/Go-SMS-verification-twilio.git
  2. Create a Twilio Account:

    • Sign up for a free Twilio account at https://www.twilio.com/.
    • Obtain your account SID and auth token from the Account Dashboard.
    • Create a Verify service and note down the service SID.
  3. Create a .env file:

    • Create a .env file in the project's root directory.

    • Add the following lines, replacing the placeholders with your actual credentials:

      TWILIO_ACCOUNT_SID=<ACCOUNT SID>
      TWILIO_AUTHTOKEN=<AUTH TOKEN>
      TWILIO_SERVICES_ID=<SERVICE ID>
  4. Install dependencies:

    go mod download
  5. Running the Server:

    go run cmd/main.go

API Documentation


Send OTP:

Send a POST request to the /otp endpoint with the following body to send an OTP to a user's phone number

Endpoint:

POST /otp

Request Body:

{
  "phoneNumber":"<phone-number-with-country-code>"
}
curl -H "Content-Type: application/json" -X POST -d '{"phoneNumber": "+91##########"}' http://localhost:8000/otp

OR

Example using REST API extension in Visual Studio Code: get-OTP.http file

POST http://localhost:8000/otp
Content-Type: application/json

{
  "phoneNumber": "+91##########"
}

Response:

{
  "status": 202,
  "message": "success",
  "data": "OTP sent successfully"
}

Verify OTP:

Verify a user's OTP by sending a POST request to the /verify endpoint with the following body that contains the phone number and the OTP code received by the user

POST /verifyOTP

Request Body:

{
  "user": {
    "phoneNumber": "<phone-number-with-country-code>"
  },
  "code": "<code here>"
}
curl -H "Content-Type: application/json" -X POST -d '{"user": {"phoneNumber": "+91##########"}, "code":"123456"}' http://localhost:8000/verifyOTP

OR

Example using REST API extension in Visual Studio Code: verifyOTP.http file

POST http://localhost:8000/verifyOTP
Content-Type: application/json

{
  "user": {
    "phoneNumber": "+91##########"
  },
  "code":"123456"
}

Response:

{
  "status": 202,
  "message": "success",
  "data": "OTP verified successfully"
}

Successfull HTTP Request's Response:

HTTP REQUEST IMAGE

go-sms-verification-twilio's People

Contributors

jaybaba8085 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.