One-time user authentication via SMS using Django and Twilio

I am writing a back-end in Django for the mobile application that I am creating. I need to authenticate the user when I first open the mobile application via SMS to make sure that he is a real person. What should happen is this: the user enters the phone number in the application, then the server sends an SMS message to the user with the authentication code, then the user enters the authentication code in the application, and the server verifies that the code they entered in the application is the same, which they received via SMS.

I need to use Twilio with my Django project. I just need to know what would be the best way to do this? The outside of this (mobile application) is not what I'm asking for, I'm asking about the code that needs to be implemented on the internal server. I'm struggling to find up-to-date documentation for django-twilio integration that can do this.

+6
source share
2 answers

The Twilio preacher and the accompanying twangio django are here.

What you want to build is very easy to do, I can describe the steps for you here:

  • Create a Django model that stores the user number and the generated access code
  • When a new user is created, take their number and send an SMS code using the Twilio REST API .
  • When they enter the password that you sent, cross-reference it with that stored in the database.
  • If the number is correct: check them, if not, tell them that this is wrong, and offer to send them an SMS again.

I hope this is clear if you have any more questions, feel free to contact us at paul@twilio.com

+17
source

You can use django-passcode as an application in your project. It provides an API for "registering" a mobile number and "checking" through an SMS-based access code. It uses the mobile number and device identifier as unique. It also generates and returns a token for future authorization requests from the mobile application. You can use Twilio or any other api SMS message to send SMS.

https://github.com/sgurminder/django-passcode

I appreciate your feedback for django-passcode

+2
source

Source: https://habr.com/ru/post/977664/


All Articles