aaronn / django-rest-framework-passwordless

Passwordless Auth for Django REST Framework
MIT License
717 stars 156 forks source link

Unable to send you a login code. Try again later. #26

Closed afansv closed 4 years ago

afansv commented 5 years ago

Hello, everyone! I have a problem with sms auth using Twilio. That's my settings:

PASSWORDLESS_AUTH = {
    'PASSWORDLESS_AUTH_TYPES': ['MOBILE'],
    'PASSWORDLESS_MOBILE_NOREPLY_NUMBER': 'secret',
    'PASSWORDLESS_USER_MARK_MOBILE_VERIFIED': True,
}

And .env:

TWILIO_ACCOUNT_SID=secret
TWILIO_AUTH_TOKEN=secret

The problem is this error message (requesting /auth/mobile/):

{
    "detail": "Unable to send you a login code. Try again later."
}

Can you help me? I really upset about it. I don't think there is a problem with my Twilio credentials, because I have ho problem with this creds in console.

taime commented 5 years ago

@afansv I've found out the problem! The TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in settings is not being used. Actually this app use env vars.

This is code from utils.py

twilio_client = Client(os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN'])

As you can see... os.environ here!

So you should download this library and change this or export env vars to your environment:

This would solve the problem! export TWILIO_ACCOUNT_SID=secret export TWILIO_AUTH_TOKEN=secret

3N61N33R commented 4 years ago

Thank you @taime. This works Also, check this out https://github.com/TwilioDevEd/server-notifications-django/blob/master/.env_example

@afansv I've found out the problem! The TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN in settings is not being used. Actually this app use env vars.

This is code from utils.py

twilio_client = Client(os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN'])

As you can see... os.environ here!

So you should download this library and change this or export env vars to your environment:

This would solve the problem! export TWILIO_ACCOUNT_SID=secret export TWILIO_AUTH_TOKEN=secret

aaronn commented 4 years ago

Hey– this is mentioned in the readme:

and set the ``TWILIO_ACCOUNT_SID`` and ``TWILIO_AUTH_TOKEN`` environment
variables. 

I'll add some notes to make sure it's clearer that this is your environment and not settings file:

These are read from `os.environ`, so make sure you don't put
them in your settings file accidentally.