Go-OTP
Go realization to otp authentication
Stack:
- Redis (Save OTP and token)
- Go
- SMS provider (Megafon as example)
Schema:
- User send
phonenumber
(ex.79212345555) Go-OTP
validate itGo-OTP
generate random code (4-6 digits)- Save
phonenumber:otp
inRedis
- Generate random
token
- Save
token:phonenumber
inRedis
- Send back
token
to user and sendasync
sms code (goroutine) - User send
token + otp
- Get (Redis):
token -> phonenumber -> code
- Compare both
otps
- Send result to user
Installation:
go get https://github.com/a1k89/go-otp
How to use
- First step:
Method: POST
URL: `/generate/`
Payload: {"phone_number":"<phone_number>"}
Response: {"token": "<TOKEN>"}
- Second step:
Method: POST
URL: `/verificate/`
Payload: {"token":"<TOKEN>", "otp": "<OTP_FROM_SMS>"}
Response: {"status": true/false, "message":"success message"}