From 580b423c81aaa0ab9ce78df711dbda3ac3999eb0 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Mon, 30 Sep 2019 23:50:13 -0400 Subject: [PATCH 1/4] adding compatibility for twilio==6.x --- deux/app_settings.py | 4 ++-- deux/notifications.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/deux/app_settings.py b/deux/app_settings.py index d13260b..fe77f29 100644 --- a/deux/app_settings.py +++ b/deux/app_settings.py @@ -11,12 +11,12 @@ 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": "", } # List of settings that cannot be empty. diff --git a/deux/notifications.py b/deux/notifications.py index 50a9c1d..46ac7e8 100644 --- a/deux/notifications.py +++ b/deux/notifications.py @@ -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 @@ -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), From ef3fdfd4fba891a2e909cb7be110d21740d5587e Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Tue, 1 Oct 2019 23:11:33 -0400 Subject: [PATCH 2/4] adding explicit fields property to deux.serializers.MultiFactorAuthSerializer as creating a ModelSerializer without either the 'fields' attribute or the 'exclude' attribute has been deprecated since DRF 3.3.0, and is now disallowed --- deux/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/deux/serializers.py b/deux/serializers.py index d6905d4..4c39acd 100644 --- a/deux/serializers.py +++ b/deux/serializers.py @@ -39,6 +39,7 @@ def to_representation(self, mfa_instance): class Meta: model = mfa_settings.MFA_MODEL + fields = '__all__' class _BaseChallengeRequestSerializer(MultiFactorAuthSerializer): From 06943ced4a2689b8836d96cf465cc457979a4ba0 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 9 Apr 2020 11:50:02 -0400 Subject: [PATCH 3/4] adding customization for text message --- deux/strings.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deux/strings.py b/deux/strings.py index c1ed5c0..e51ced3 100644 --- a/deux/strings.py +++ b/deux/strings.py @@ -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 = _( @@ -32,4 +33,7 @@ SMS_SEND_ERROR = _("SMS failed to send.") #: Message body for a MFA code. -MFA_CODE_TEXT_MESSAGE = _("Two Factor Authentication Code: {code}") +try: + MFA_CODE_TEXT_MESSAGE = mfa_settings.MFA_CODE_TEXT_MESSAGE +except: + MFA_CODE_TEXT_MESSAGE = _("Two Factor Authentication Code: {code}") From 9c79683d81fc0df69d736c21655ceca170873c97 Mon Sep 17 00:00:00 2001 From: Ibrahim Date: Thu, 9 Apr 2020 11:56:39 -0400 Subject: [PATCH 4/4] adding customization for text message --- deux/app_settings.py | 1 + deux/strings.py | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/deux/app_settings.py b/deux/app_settings.py index fe77f29..06994a2 100644 --- a/deux/app_settings.py +++ b/deux/app_settings.py @@ -17,6 +17,7 @@ "TWILIO_ACCOUNT_SID": "", "TWILIO_AUTH_TOKEN": "", "TWILIO_PHONE_NUMBER": "", + "MFA_CODE_TEXT_MESSAGE": "Two Factor Authentication Code: {code}" } # List of settings that cannot be empty. diff --git a/deux/strings.py b/deux/strings.py index e51ced3..3970822 100644 --- a/deux/strings.py +++ b/deux/strings.py @@ -33,7 +33,4 @@ SMS_SEND_ERROR = _("SMS failed to send.") #: Message body for a MFA code. -try: - MFA_CODE_TEXT_MESSAGE = mfa_settings.MFA_CODE_TEXT_MESSAGE -except: - MFA_CODE_TEXT_MESSAGE = _("Two Factor Authentication Code: {code}") +MFA_CODE_TEXT_MESSAGE = mfa_settings.MFA_CODE_TEXT_MESSAGE