You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+55-39Lines changed: 55 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,5 @@
1
1
# OTP Gateway
2
+
2
3
OTP (One Time Password) Gateway is a standalone web app that provides a central gateway to verify user addresses such as e-mails and phone numbers or get a 2FA confirmations from thse addresses. An e-mail / SMTP verification provider is bundled and it is easy to write custom providers as Go plugins, for instance a plugin that uses Twilio to send out verification codes to phone numbers as text messages.
3
4
4
5
- Use the built in web UI to easily integrate with existing applications
@@ -9,55 +10,62 @@ OTP (One Time Password) Gateway is a standalone web app that provides a central
The application is agnostic of the address and the OTP or verification code involved. These are handled by provider plugins. Addresses are strings, for example, e-mail IDs, phone numbers, bank account numbers etc., and so are OTPs, for instance, 6 digit codes sent as SMSes or a penny value dropped to a bank account. The gateway pushes the OTP value to the user's target address and the user then has to view the OTP and enter it on the gateway's web view to complete the verification.
15
16
16
17
## Providers
18
+
17
19
Providers are written as [Go plugins](https://golang.org/pkg/plugin/) that can be dynamically loaded into the gateway. An SMTP provider is bundled that enables e-mail address verifications by sending an OTP / verification link to user's e-mails. Refer to `providers/smtp/smtp.go`. To write a custom provider, copy the `smtp` plugin and change the methods to conform to the `otpgateway.Provider` interface and compile it as a go plugin (see the `Makefile`).
18
20
19
21
-[solsms](https://github.com/knadh/otpgateway-solsms) - SMS provider for Solutions Infini (Indian gateway)
20
22
21
23
# Usage
22
-
Download the latest release from the [releases page](https://github.com/knadh/otpgateway/releases) or clone this repository and run `make deps && make build`. Redis is a requirement.
24
+
25
+
Download the latest release from the [releases page](https://github.com/knadh/otpgateway/releases) or clone this repository and run `make deps && make build`. OTP Gateway requires a Redis installation.
26
+
23
27
- Copy config.toml.sample to config.toml and edit the configuration
24
-
- Run `./otpgateway --prov smtp`
25
-
28
+
- Run `./otpgateway --prov smtp.prov`
29
+
26
30
### Built in UI
31
+
27
32
1. Generate an OTP for a user server side in your application:
28
-
`curl -u "myAppName:mySecret" -X PUT -d "to=john@doe.com&provider=smtp" localhost:9000/api/otp/uniqueIDForJohnDoe`
33
+
`curl -u "myAppName:mySecret" -X PUT -d "to=john@doe.com&provider=smtp" localhost:9000/api/otp/uniqueIDForJohnDoe`
29
34
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:
30
-
`curl -u "myAppName:mySecret" -X POST localhost:9000/api/otp/uniqueIDForJohnDoe/status`
35
+
`curl -u "myAppName:mySecret" -X POST localhost:9000/api/otp/uniqueIDForJohnDoe/status`
31
36
32
37
### Your own UI
38
+
33
39
Use the APIs described below to build your own UI.
34
40
35
41
# API reference
42
+
36
43
### List providers
44
+
37
45
`curl localhost:9000/api/providers`
46
+
38
47
```json
39
48
{
40
49
"status": "success",
41
-
"data": [
42
-
"smtp"
43
-
]
50
+
"data": ["smtp"]
44
51
}
45
52
```
46
53
47
54
### Initiate an OTP for a user
55
+
48
56
```shell
49
57
curl -u "myAppName:mySecret" -X PUT -d "to=john@doe.com&provider=smtp&extra={\"yes\": true}" localhost:9000/api/otp/uniqueIDForJohnDoe
|: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. |
55
-
| provider | ID of the provider plugin to use for verification. The bundled e-mail provider's ID is "smtp". |
56
-
| 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. |
57
-
| channel_description | (optional) Description to show to the user on the OTP verification page. If left empty, it'll show the default description or help text from the provider plugin. |
58
-
| address_description | (optional) Description to show to the user on the address collection page. If left empty, it'll show the default description or help text from the provider plugin. |
59
-
| otp | (optional) The OTP or code to send to the user for verification. If this is left empty, a random OTP is generated and sent |
60
-
| extra | (optional) An extra payload (JSON string) that will be returned with the OTP |
|: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. |
63
+
| provider | ID of the provider plugin to use for verification. The bundled e-mail provider's ID is "smtp".|
64
+
| 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.|
65
+
| channel_description | (optional) Description to show to the user on the OTP verification page. If left empty, it'll show the default description or help text from the provider plugin. |
66
+
| address_description | (optional) Description to show to the user on the address collection page. If left empty, it'll show the default description or help text from the provider plugin. |
67
+
| otp | (optional) The OTP or code to send to the user for verification. If this is left empty, a random OTP is generated and sent|
68
+
| extra | (optional) An extra payload (JSON string) that will be returned with the OTP|
Every incorrect validation here increments the attempts before further attempts are blocked.
86
94
`curl -u "myAppName:mySecret" -X POST -d "action=check&otp=354965" localhost:9000/api/otp/uniqueIDForJohnDoe`
87
95
@@ -94,7 +102,7 @@ Every incorrect validation here increments the attempts before further attempts
94
102
"to": "john@doe.com",
95
103
"channel_description": "",
96
104
"address_description": "",
97
-
"extra": {"yes": true},
105
+
"extra": {"yes": true},
98
106
"provider": "smtp",
99
107
"otp": "354965",
100
108
"max_attempts": 5,
@@ -107,6 +115,7 @@ Every incorrect validation here increments the attempts before further attempts
107
115
```
108
116
109
117
### Check whether an OTP request is verified
118
+
110
119
This is used to confirm verification after a callback from the built in UI flow.
111
120
`curl -u "myAppName:mySecret" -X POST localhost:9000/api/otp/uniqueIDForJohnDoe/status`
112
121
@@ -119,7 +128,7 @@ This is used to confirm verification after a callback from the built in UI flow.
119
128
"to": "john@doe.com",
120
129
"channel_description": "",
121
130
"address_description": "",
122
-
"extra": {"yes": true},
131
+
"extra": {"yes": true},
123
132
"provider": "smtp",
124
133
"otp": "354965",
125
134
"max_attempts": 5,
@@ -133,31 +142,38 @@ This is used to confirm verification after a callback from the built in UI flow.
133
142
or an error such as
134
143
135
144
```json
136
-
{"status":"error","message":"OTP not verified"}
145
+
{"status":"error","message":"OTP not verified"}
137
146
```
138
147
139
-
140
148
# Javascript plugin
149
+
141
150
The gateway comes with a Javascript plugin that enables easy integration of the verification flow into existing application. 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, and once the user finishes the verification, gives you a callback.
142
151
143
152
```html
144
153
<!-- The id #otpgateway-script is required for the script to work //-->
0 commit comments