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

add vonage provider #15

Merged
merged 1 commit into from
Nov 27, 2020
Merged
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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Flexible authentication for web, mobile, desktop and hybrid apps. It can be used

and service providers:
- Twilio
- SendGrid (to be specified)
- Nexmo (to be done)
- Vonage (Nexmo)
- Amazon SNS (to be done)
- ...add yours

Expand Down
2 changes: 1 addition & 1 deletion multauth/api/auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
'SignupVerificationUserSerializer',
# 'ResetSerializer', 'ResetEmailSerializer',

'TokenSerializer',
'TokenSerializer',authenticate
)


Expand Down
4 changes: 3 additions & 1 deletion multauth/devices/phone.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from importlib import import_module
from django.db import models
from django.contrib.auth.hashers import check_password, is_password_usable, make_password
from django.template.loader import get_template
Expand All @@ -12,7 +13,8 @@


try:
PhoneProvider = settings.MULTAUTH_DEVICE_PHONE_PROVIDER
PhoneProviderName = settings.MULTAUTH_DEVICE_PHONE_PROVIDER
PhoneProvider = import_module(PhoneProviderName)
except AttributeError:
from ..providers.twilio import TwilioProvider
PhoneProvider = TwilioProvider
Expand Down
2 changes: 1 addition & 1 deletion multauth/providers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .mail import MailProvider
from .nexmo import NexmoProvider
from .vonage import VonageProvider
from .twilio import TwilioProvider
33 changes: 0 additions & 33 deletions multauth/providers/nexmo.py

This file was deleted.

4 changes: 4 additions & 0 deletions multauth/providers/twilio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# see
# https://www.twilio.com/docs/libraries/python
# https://github.com/twilio/twilio-python/
if TWILIO_ACCOUNT_SID:
twilio = Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
else:
Expand All @@ -30,6 +31,9 @@ def __init__(self, to, message='', *args, **kwargs):
self.message = message
# RESERVED # self.fail_silently = kwargs.get('fail_silently', False)

# todo:
# handle exceptions
# https://github.com/twilio/twilio-python/#handling-exceptions
def _send(self):
if not self.to:
return
Expand Down
45 changes: 45 additions & 0 deletions multauth/providers/vonage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from django.conf import settings
from vonage.rest import Client, Sms

from .abstract import AbstractProvider


VONAGE_API_KEY = getattr(settings, 'MULTAUTH_PROVIDER_VONAGE_API_KEY', None)
VONAGE_API_SECRET = getattr(settings, 'MULTAUTH_PROVIDER_VONAGE_API_SECRET', None)
vonage_from = getattr(settings, 'MULTAUTH_PROVIDER_VONAGE_BRAND_NAME', None)

# see
# https://github.com/vonage/vonage-python-sdk
if VONAGE_API_KEY:
vonage = Client(key=TWILIO_ACCOUNT_SID, secret=TWILIO_AUTH_TOKEN)
sms = Sms(client)
else:
print('Vonage: running in mock mode. Set "account sid" and other params.')
vonage = None


class VonageProvider(AbstractProvider):

def __init__(self, to, message='', *args, **kwargs):
"""
Args:
@to (str)
@message (str)
@fail_silently (bool): optional
"""
self.to = to
self.message = message
# RESERVED # self.fail_silently = kwargs.get('fail_silently', False)

def _send(self):
if not self.to:
return

if vonage:
sms.send_message({
'to': self.to,
'from': vonage_from,
'body': self.message,
})
else:
print('Vonage: to %s, message "%s"' % (self.to, self.message))
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def read(f):

setup(
name='django-multifactor-authentication',
version='0.9.5',
keywords='django authentication multifactor mfa 2fa 3fa user signin signup twillio sendgrid nexmo sns',
version='0.9.7',
url='https://github.com/andrenerd/django-multifactor-authentication',
license='BSD',
description='Flexible authentication for web, mobile, desktop and hybrid apps. It can be used for 1fa, 2fa and mfa cases.',
Expand All @@ -25,9 +26,9 @@ def read(f):
'django-phonenumber-field>=3.0.1',
'django_otp>=0.4.3',
],
extras_require=[
'djangorestframework>=3.10.3, <4.0.0',
],
extras_require={
'api': ['djangorestframework>=3.10.3, <4.0.0'],
},
python_requires='>=3.5',
zip_safe=False,
classifiers=[
Expand Down