A serverless aproach to managing the two-factor authentication (2fa) tokens for a single account and deliver them by sms.
A zeit account will be needed to perform the deployments, if you're not registere a free account can be created here.
To send the sms a Twilio account with its corresponding sid and auth token credentials for further reading
NOTE: Although Twilio offers a free trial, after said period there will be chargers for the service in the form of a set price for each sms based on the destination country as well as the monthly rent of a phone number.
# yarn
yarn global add vercel
# npm
npm i -g vercel
Actions such as deployment will require that zeit has been authenticated for the current machine, it can be done with:
vercel login
This process will ask the user to introduce their registered email and then to click on a verify link sent through the email that they'll get.
To deply a new version simply run the command:
vercel
Once the environment has been set up it's time to set our credentials and authentication secrets. By the fault there are 5 secrets that must be set and they can be found in the now.json file at the "env" key.
{
"version": 2,
"name": "single_user_2fa",
"env": {
"SECRET": "@2fa_secret",
"TWILLIO_ACCOUND_SID": "@twillio_account_sid",
"TWILLIO_AUTH_TOKEN": "@twillio_auth_token",
"TO_NUMBER": "@twillio_to_number",
"FROM_NUMBER": "@twillio_from_number"
},
"builds": [
{ "src": "*.py", "use": "@now/python" }
]
}
Setting up the new secrets
vercel secret add 2fa_secret 2fa_secret_here
vercel secret add twillio_account_sid twillio_api_sid_here
vercel secret add twillio_auth_token twillio_api_auth_here
vercel secret add twillio_to_number destination_phone_here
vercel secret add twillio_from_number yout_twillio_number_here
Note: If the secrets are changed a new version of the code must be deployed for the changes to take effect.
Credit goes to Patrick Mylund Nielsen for his python implementation of the 2fa
- Leading 0s in codes are omited by the algorithm
- Likely happens with any number of continues leading zeros