Skip to content

Commit 9b34c55

Browse files
committed
update to make configurable callback
1 parent a5c065b commit 9b34c55

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ DEFAULTS = {
308308
# What function is called to construct a serializer for drf tokens when
309309
# exchanging a passwordless token for a real user auth token.
310310
'PASSWORDLESS_AUTH_TOKEN_SERIALIZER': 'drfpasswordless.serializers.TokenResponseSerializer'
311-
311+
# You can set the callback to send the tokens with:
312+
'PASSWORDLESS_EMAIL_CALLBACK': 'drfpasswordless.utils.send_email_with_callback_token'
313+
'PASSWORDLESS_SMS_CALLBACK': 'drfpasswordless.utils.send_sms_with_callback_token'
312314
}
313315
```
314316

drfpasswordless/services.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
from django.utils.module_loading import import_string
2+
13
from drfpasswordless.settings import api_settings
24
from drfpasswordless.utils import (
35
create_callback_token_for_user,
4-
send_email_with_callback_token,
5-
send_sms_with_callback_token
66
)
77

88

@@ -15,9 +15,9 @@ def send_token(user, alias_type, token_type, **message_payload):
1515
if user.pk in api_settings.PASSWORDLESS_DEMO_USERS.keys():
1616
return True
1717
if alias_type == 'email':
18-
send_action = send_email_with_callback_token
18+
send_action = import_string(api_settings.PASSWORDLESS_EMAIL_CALLBACK)
1919
elif alias_type == 'mobile':
20-
send_action = send_sms_with_callback_token
20+
send_action = import_string(api_settings.PASSWORDLESS_SMS_CALLBACK)
2121
# Send to alias
2222
success = send_action(user, token, **message_payload)
2323
return success

drfpasswordless/settings.py

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@
8585

8686
# A dictionary of demo user's primary key mapped to their static pin
8787
'PASSWORDLESS_DEMO_USERS': {},
88+
89+
'PASSWORDLESS_EMAIL_CALLBACK': 'drfpasswordless.utils.send_email_with_callback_token',
90+
'PASSWORDLESS_SMS_CALLBACK': 'drfpasswordless.utils.send_sms_with_callback_token',
8891
}
8992

9093
# List of settings that may be in string import notation.

0 commit comments

Comments
 (0)