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: two_factor_authentication/twilio_verify_2fa.md
+33-9Lines changed: 33 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -49,18 +49,19 @@ Note that these keys are private and should not be committed to version control.
49
49
50
50
## Create a simple flask application with basic form validation
51
51
52
-
I will not go into the details of how to create a simple flask application. If you are new to Flask, you can [learn how here](https://github.com/GitauHarrison/notes/blob/master/start_flask_server.md). A complete flask starter project is available on [GitHub](https://github.com/GitauHarrison/starting-a-flask-server). You will need to install and work with a database, `flask-wtf` and `flask-login` to complete the project.
52
+
I will not go into the details of how to create a simple flask application. If you are new to Flask, I recommend that you begin [here](https://github.com/GitauHarrison/notes/blob/master/start_flask_server.md). A complete flask starter project is available on [GitHub](https://github.com/GitauHarrison/starting-a-flask-server). You will also need to learn how to create and work with web forms, a database, and user sessions to complete this project.
53
+
54
+
55
+
## Integrate Twilio Verify with your flask application
56
+
57
+
When a user first creates an account, they will have the option to enable two-factor authentication on their profile page. When they click the "Enable 2FA" link, they will be requested to provide their phone number which will be used to get a verification code. Subsequent logins will require them to enter the verification code before they can access their accounts.
53
58
54
59
Once you have your project up and running, you will need to install `twilio` in your virtual environment.
55
60
56
61
```python
57
62
(venv) $ pip3 install "twilio>=6.17.0"
58
63
```
59
64
60
-
## Integrate Twilio Verify with your flask application
61
-
62
-
When a user first creates an account, they will have the option to enable two-factor authentication on their profile page. When they click the "Enable 2FA" link, they will be requested to provide their phone number which will be used to get a verification code. Subsequent logins will require them to enter the verification code before they can access their accounts.
63
-
64
65
### Integration table of contents
65
66
66
67
1.[Testing](#testing)
@@ -199,7 +200,15 @@ class PhoneForm(FlaskForm):
199
200
200
201
```
201
202
202
-
Notice that I am using the `phonenumbers` library to validate the phone number. This library is used to validate phone numbers in the helper `validate_phone` method. Typically, its usage is as follows:
203
+
Notice that I am using the `phonenumbers` library to validate the phone number. This library is used to validate phone numbers in the helper `validate_phone` method. Before you can use it, you have to install it in your virtual environment.
The `request_verification_token` function is used to generate a one-time token. A call to this function is defined below. For now, let us focus on creating this template.
256
+
246
257
##### Improved phone number form
247
258
248
259
Since users of the application may be from different nationalities, it would help improve their experience if they could enter their respective phone numbers in the international format.
result = verify.verifications_check(to=phone, code=token)
516
+
result = verify.verification_checks.create(to=phone, code=token)
506
517
return result.status =='approved'
507
518
except TwilioException as e:
508
519
returnFalse
509
520
```
510
521
511
522
#### Disable 2FA
512
523
513
-
With the state of 2FA updated, we can now implement the `disable_2fa` view function. This will allow a user to disable 2FA by removing his phone from the database.
524
+
With the state of 2FA updated, we can now implement the `disable_2fa` view function. This will allow a user to disable 2FA by removing his phone number from the database.
0 commit comments