Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding compatibility for twilio==6.x #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions deux/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
DEFAULTS = {
"BACKUP_CODE_DIGITS": 12,
"MFA_CODE_NUM_DIGITS": 6,
"STEP_SIZE": 30,
"MFA_MODEL": "deux.models.MultiFactorAuth",
"SEND_MFA_TEXT_FUNC": "deux.notifications.send_mfa_code_text_message",
"STEP_SIZE": 30,
"TWILIO_ACCOUNT_SID": "",
"TWILIO_AUTH_TOKEN": "",
"TWILIO_SMS_POOL_SID": "",
"TWILIO_PHONE_NUMBER": "",
"MFA_CODE_TEXT_MESSAGE": "Two Factor Authentication Code: {code}"
}

# List of settings that cannot be empty.
Expand Down
8 changes: 4 additions & 4 deletions deux/notifications.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import absolute_import, unicode_literals

from twilio.rest import TwilioRestClient
from twilio.rest.exceptions import TwilioRestException
from twilio.rest import Client
from twilio.base.exceptions import TwilioRestException

from deux import strings
from deux.app_settings import mfa_settings
Expand All @@ -26,13 +26,13 @@ def send_mfa_code_text_message(mfa_instance, mfa_code):

sid = mfa_settings.TWILIO_ACCOUNT_SID
token = mfa_settings.TWILIO_AUTH_TOKEN
twilio_num = mfa_settings.TWILIO_SMS_POOL_SID
twilio_num = mfa_settings.TWILIO_PHONE_NUMBER
if not sid or not token or not twilio_num:
print("Please provide Twilio credentials to send text messages. For "
"testing purposes, the MFA code is {code}".format(code=mfa_code))
return

twilio_client = TwilioRestClient(sid, token)
twilio_client = Client(sid, token)
try:
twilio_client.messages.create(
body=strings.MFA_CODE_TEXT_MESSAGE.format(code=mfa_code),
Expand Down
1 change: 1 addition & 0 deletions deux/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def to_representation(self, mfa_instance):

class Meta:
model = mfa_settings.MFA_MODEL
fields = '__all__'


class _BaseChallengeRequestSerializer(MultiFactorAuthSerializer):
Expand Down
3 changes: 2 additions & 1 deletion deux/strings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals

from django.utils.translation import ugettext_lazy as _
from deux.app_settings import mfa_settings

#: Error if user submits both MFA and backup code for authentication.
BOTH_CODES_ERROR = _(
Expand Down Expand Up @@ -32,4 +33,4 @@
SMS_SEND_ERROR = _("SMS failed to send.")

#: Message body for a MFA code.
MFA_CODE_TEXT_MESSAGE = _("Two Factor Authentication Code: {code}")
MFA_CODE_TEXT_MESSAGE = mfa_settings.MFA_CODE_TEXT_MESSAGE