This is a microservice to generate and verify a 6 digit verification code. It can be applied in the common verification use case.
Basic use cases
- The verification code is generated as per mobile number and will expire in 2 minutes.
- The verification code generation is limited to 3 times a day per mobile number. After exceeding the limit, users have to retry in the next day.
Run docker-compose up --build
-
Endpoint:
/ping
Request:
curl -X GET 'localhost:8080/ping'
Response:
pong
-
Endpoint:
/generate
Request:
curl -X POST 'localhost:8080/generate' -H 'Content-Type: application/json' -d '{"phone_number": "0487654321"}'
Response:
true
-
Endpoint:
/verify
Request:
curl -X POST 'localhost:8080/verify' -H 'Content-Type: application/json' -d '{"phone_number": "0487654321","verification_code": "572631"}'
Response:
true
The verification code generated via
/generate
is stored in Redis. A text message will be sent to the designated mobile. You can also get it via the commands below.
- Run
docker run -it --rm --network go-verification-code_app-tier bitnami/redis:latest redis-cli -h redis
to connect to theredis
container. - Get the verfication code by key, e.g:
get code:+61487654321
. - Then you can use the verfication code in the
/verify
request.
MessageMedia
- MessageMedia is used as an SMS service to send the verification code via text messages.
- You can replace the SMS_AUTHORIZATION value in the config.env file with your own MessageMedia API key/secret pair to make it work.
- In testing, the Australian (+61) mobile number is used.
- Refer to https://messagemedia.github.io/documentation/ for more information.
Alternatively, you can adopt other SMS service by implementing the SmsClientInterface
interface.