Code Monkey home page Code Monkey logo

knadh / otpgateway Goto Github PK

View Code? Open in Web Editor NEW
419.0 17.0 79.0 158 KB

Standalone server for user address and OTP verification flows with pluggable providers (e-mail, SMS, bank penny drops etc.)

License: MIT License

Makefile 1.46% Go 79.19% HTML 6.77% JavaScript 3.21% Smarty 2.32% CSS 6.80% Dockerfile 0.25%
otp-verification otp-generator otp-applications verification-code mobile-number-verification email-verification sms-verification

otpgateway's Introduction

OTP Gateway

OTP (One Time Password) Gateway is a standalone web server that provides a central gateway to verify user addresses such as e-mails and phone numbers, and to send 2FA confirmations to such addresses.

  • Use the built in web UI to easily integrate with existing applications.
  • Use the HTTP/JSON APIs to build your own UI.
  • Basic multi-tenancy with namespace+secret BasicAuth for seggregating applications.

address otp email-otp

Built-in providers

  • SMTP
  • AWS Pinpoint SMS
  • Kaleyra SMS, WhatsApp

Webhook providers

Any external provider can be integrated by defining one or more webhook providers in the config. A JSON payload is posted to the webhook endpoint whenever an OTP is generated.

How does it work?

The application is agnostic of the user's "address" and the OTP / verification codes. These are handled by providers.

  • Addresses are strings, for example, e-mail IDs, phone numbers, bank account numbers etc.
  • OTPs are also just strings, for instance, 6 digit codes sent as SMSes or a penny value dropped to a bank account.

The gateway sends the OTP value to the user's address using a provider (an upstream that takes the OTP + message and sends it to the user) and the user then has to read the OTP and enter it on the gateway's web view to complete the verification.

Usage

Download the latest release from the releases page.

  • Copy config.sample.toml to config.toml and edit the configuration.
  • Run ./otpgateway
  • Refer to the API reference to send OTPs.

Built in UI

  1. Generate an OTP for a user server side in your application: curl -u "myAppName:mySecret" -X PUT -d "[email protected]&provider=smtp" localhost:9000/api/otp/uniqueIDForJohnDoe
  2. Use the OTPGateway() Javascript function (see the Javascript plugin section) to initiate the modal UI on your webpage. On receiving the Javascript callback, post it back to your application and confirm that the OTP is indeed verified: curl -u "myAppName:mySecret" -X POST localhost:9000/api/otp/uniqueIDForJohnDoe/status

Your own UI

Use the APIs described below to build your own UI.

API reference

List providers

curl -u "myAppName:mySecret" localhost:9000/api/providers

{
  "status": "success",
  "data": ["smtp"]
}

Initiate an OTP for a user

curl -u "myAppName:mySecret" -X PUT -d "[email protected]&provider=smtp&extra={\"yes\": true}" localhost:9000/api/otp/uniqueIDForJohnDoe
param description
:id (optional) A unique ID for the user being verified. If this is not provided, an random ID is generated and returned. It's good to send this as a permanent ID for your existing users to prevent users from indefinitely trying to generate OTPs. For instance, if your user's ID is 123 and you're verifying the user's e-mail, a simple ID can be MD5("email.123"). Important. The ID is only unique per namespace and not per provider.
provider ID of the provider plugin to use for verification. The bundled e-mail provider's ID is "smtp".
to (optional) The address of the user to verify, for instance, an e-mail ID for the "smtp" provider. If this is left blank, a view is displayed to collect the address from the user.
channel_description (optional) Description to show to the user on the OTP verification page. If not provided, it'll show the default description or help text from the provider plugin.
address_description (optional) Description to show to the user on the address collection page. If not provided, it'll show the default description or help text from the provider plugin.
otp (optional) The OTP or code to send to the user for verification. If not provided, a random OTP is generated and sent
ttl (optional) OTP expiry in seconds. If not provided, the default value from the config is used.
max_attempts (optional) Maximum number of OTP verification attempts. If not provided, the default value from the config is used.
skip_delete (optional) After a successful OTP verification, the OTP is deleted. If this is set true true, OTP is not deleted and is let to expire gradually.
extra (optional) An extra payload (JSON string) that will be returned with the OTP
{
  "status": "success",
  "data": {
    "namespace": "myAppName",
    "id": "uniqueIDForJohnDoe",
    "to": "[email protected]",
    "channel_description": "",
    "address_description": "",
    "extra": { "yes": true },
    "provider": "smtp",
    "otp": "354965",
    "max_attempts": 5,
    "attempts": 5,
    "closed": false,
    "ttl": 300,
    "url": "http://localhost:9000/otp/myAppName/uniqueIDForJohnDoe"
  }
}

Validate an OTP entered by the user

Every incorrect validation here increments the attempts before further attempts are blocked. Once the OTP is verified, it is deleted, unless skip_delete=true is passed in the params. curl -u "myAppName:mySecret" -X POST -d "action=check&otp=354965" localhost:9000/api/otp/uniqueIDForJohnDoe

{
  "status": "success",
  "data": {
    "namespace": "myAppName",
    "id": "uniqueIDForJohnDoe",
    "to": "[email protected]",
    "channel_description": "",
    "address_description": "",
    "extra": { "yes": true },
    "provider": "smtp",
    "otp": "354965",
    "max_attempts": 5,
    "attempts": 5,
    "closed": false,
    "ttl": 300,
    "url": "http://localhost:9000/otp/myAppName/uniqueIDForJohnDoe"
  }
}

Check whether an OTP request is verified

This is used to confirm verification after a callback from the built in UI flow. curl -u "myAppName:mySecret" -X POST localhost:9000/api/otp/uniqueIDForJohnDoe/status

{
  "status": "success",
  "data": {
    "namespace": "myAppName",
    "id": "uniqueIDForJohnDoe",
    "to": "[email protected]",
    "channel_description": "",
    "address_description": "",
    "extra": { "yes": true },
    "provider": "smtp",
    "otp": "354965",
    "max_attempts": 5,
    "attempts": 5,
    "closed": false,
    "ttl": 300
  }
}

or an error such as

{ "status": "error", "message": "OTP not verified" }

The closed field indicates whether the OTP has been validated by the user and has been "closed".

Javascript plugin

The gateway comes with a Javascript plugin that enables easy integration of the verification UI into existing applications. Once a server side call to generate an OTP is made and a namespace and id are obtained, calling OTPGateway() opens the verification UI in a modal popup. Upon completion of verification by the user, a callback is triggered.

<!-- The id #otpgateway-script is required for the script to work //-->
<script
  id="otpgateway-script"
  src="http://localhost:9000/static/otp.js"
></script>
<script>
  // 1. Make a call to the server to generate and send an OTP and return the
  // the :namespace and :id for the OTP.
  // 2. Invoke the verification UI for the user with the namespace and id values,
  // and a callback which is triggered when the user finishes the flow.
  OTPGateway(
    namespaceVal,
    idVal,
    function(nm, id) {
      console.log("finished", nm, id);

      // 3. Post the namespace and id to your server that will make the
      // status request to the gateway and on success, update the user's
      // address in your records as it's now verified.
    },
    function() {
      console.log("cancelled");
    }
  );
</script>

Licensed under the MIT license.

otpgateway's People

Contributors

joeirimpan avatar josejibin avatar knadh avatar mr-karan avatar rhnvrm avatar shridarpatil avatar vishalvshekkar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

otpgateway's Issues

Dockerfile does not contain reproducible build

Dockerfile content does not contain instructions to build the binary but instead assumes a binary already exists in the folder and attempts to copy it.

It should instead contain steps to build the binary. Therefore using docker to pull from https://hub.docker.com/r/kailashnadh/otpgateway is pointless.

It is also very concerning for traceable builds considering that right now if you run ./otpgateway --version on the release builds it returns unknown

Bridging or gluing with authentication service

Are there any best practices to integrate with the authentication service?

Currently the response comes to the frontend. How to check that in backend so that the users can't fake it to pass the screen?

Guide from Installation To Usage

Respected @knadh @mr-karan sir's,
Thanks a lot for making such amazing projects ๐Ÿ˜,
I am new to integrate open source projects to ReactJs applications. But I need to use this functionalities of OTPGATEWAY for verifying Email and Phone number. I am eagerly waiting to integrate OTP verification ๐Ÿ˜…๐Ÿ˜œ.

So I request you to please share your valuable information to use and integrate them. ๐Ÿ™

Thank You sir

Installation Procedure

It's bit difficult to install and run locally. Please provide installation setup or commands if possible.
I don't have any knowledge on GO Programming Language....
Thank You.

installing

we are finding it extremely hard to properly install. pls any guide or video would do

Issue with OTP attempts

If someone is on 5/6 attempt i.e one attempt left

And enters a correct OTP for the final try & clicks on verify

Screenshot from 2022-01-26 17-09-56

The user would see Too many attempts. Please retry after %0.f seconds

Since the OTP was correct, shouldn't the OTP get verified?

just an inquiry

can i use this script to verify my twitter account ? , and thanks a lot

feature request - redis pub/sub or webhook on completion of verification

At present it seems the behavior is that, after an otp code has been sent to a user, we have to constantly poll the status endpoint ( for the duration set in the ttl variable ) in order to check whether the otp code has been verified.

Would it not relieve the need to keep polling if you were to push a message onto a redis pub/sub channel once the code has been verified? or call a webhook?

I think this could help easier integration with the backend or other authentication systems.

Feature Request: IP Based Ratelimits

Currently the max_attempts are limited to the id of an OTP. I'm not sure if this is exactly out of scope of OTPGateway, but does it make sense to include an IP-Based Rate limits, especially since OTPGateway is meant to be a standalone server.

Sure, we could use NGINX/HAProxy or other proxies but that's one extra dependency for a perfectly standalone server app.

Thoughts? And if you think we can add this, I'd like to take it up.

Thanks!

Info - GLIBC 2.32 requirement in release binaries

Just for your information, your release binaries seem to have been compiled with a system which has GLIBC 2.32
$ ldd --version
As a result, users of the release binaries must also have at least the same version present on their system or the binaries throw an error.
It might be useful to put that information in the README or build the binaries on a system with a lower version
the current GLIBC versions on debian-based systems:
Ubuntu 20.10 : 2.32
Ubuntu 20.04 : 2.31
Debian Buster : 2.28
Ubuntu 18.04 : 2.27

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.