1
- .. image:: https://travis-ci.org/aaronn/django-rest-framework-passwordless.svg?branch=master
2
- :target: https://travis-ci.org/aaronn/django-rest-framework-passwordless
3
-
1
+ ![ ci-image]
4
2
5
3
drfpasswordless is a quick way to integrate ‘passwordless’ auth into
6
4
your Django Rest Framework project using a user’s email address or
@@ -17,77 +15,79 @@ Callback tokens by default expire after 15 minutes.
17
15
Example Usage:
18
16
==============
19
17
20
- ::
21
-
18
+ ``` bash
22
19
curl -X POST -d “email=aaron@email.com” localhost:8000/auth/email/
20
+ ```
23
21
24
22
Email to aaron@email.com :
25
23
26
- ::
27
-
28
- …
24
+ ```
25
+ ...
29
26
<h1>Your login token is 815381.</h1>
30
- …
27
+ ...
28
+ ```
31
29
32
30
Return Stage
33
31
34
- ::
35
-
32
+ ``` bash
36
33
curl -X POST -d " token=815381" localhost:8000/callback/auth/
37
34
38
35
> HTTP/1.0 200 OK
39
36
> {" token" :" 76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e”}
37
+ ` ` `
40
38
41
39
Requirements
42
40
============
43
41
44
- ::
45
-
46
- - Python (2.7, 3.4, 3.5, 3.6+)
47
- - Django (1.8, 1.9, 1.10, 1.11+)
48
- - Django Rest Framework + AuthToken (3.4, 3.5, 3.6+)
49
- - Python-Twilio (Optional, for mobile.)
50
-
42
+ ` ` `
43
+ - Python (3.6+)
44
+ - Django (2.0+)
45
+ - Django Rest Framework + AuthToken (3.6+)
46
+ - Python-Twilio (Optional, for mobile.)
47
+ ` ` `
51
48
52
49
Install
53
50
=======
54
51
55
52
1. Install drfpasswordless
56
53
57
- ::
58
-
59
- pip install drfpasswordless
60
-
61
-
54
+ ` ` `
55
+ pipenv install drfpasswordless
56
+ ` ` `
57
+
62
58
2. Add Django Rest Framework’s Token Authentication to your Django Rest
63
59
Framework project.
64
60
65
- ::
66
-
61
+ ` ` ` python
67
62
REST_FRAMEWORK = {
68
63
'DEFAULT_AUTHENTICATION_CLASSES':
69
64
('rest_framework.authentication.TokenAuthentication',
70
65
)}
71
66
72
67
INSTALLED_APPS = [
73
- // …
68
+ ...
74
69
'rest_framework',
75
70
'rest_framework.authtoken',
76
71
'drfpasswordless',
72
+ ...
77
73
]
74
+ ` ` `
78
75
79
- And run `` manage.py migrate `` .
76
+ And run
77
+ ` ` ` bash
78
+ python manage.py migrate
79
+ ` ` `
80
80
81
81
3. Set which types of contact points are allowed for auth in your
82
82
Settings.py. The available options are ` ` EMAIL` ` and ` ` MOBILE` ` .
83
83
84
- ::
85
-
86
- PASSWORDLESS_AUTH = {
87
- //…
88
- ‘PASSWORDLESS_AUTH_TYPES’: [‘EMAIL’, ‘MOBILE’],
89
- //…
90
- }
84
+ ` ` ` python
85
+ PASSWORDLESS_AUTH = {
86
+ ..
87
+ ' PASSWORDLESS_AUTH_TYPES ' : [ ' EMAIL ' , ' MOBILE ' ],
88
+ ..
89
+ }
90
+ ` ` `
91
91
92
92
By default drfpasswordless looks for fields named ` ` email` ` or ` ` mobile` `
93
93
on the User model. If an alias provided doesn’t belong to any given user,
@@ -101,36 +101,37 @@ Install
101
101
102
102
4. Add ` ` drfpasswordless.urls` ` to your urls.py
103
103
104
- ::
105
-
104
+ ` ` ` python
106
105
urlpatterns = [
107
- // ..
108
- url(r'^ ', include('drfpasswordless.urls')),
109
- // ..
106
+ ..
107
+ path( ' ' , include(' drfpasswordless.urls' )),
108
+ ..
110
109
]
111
-
110
+ ` ` `
112
111
113
112
5. You can now POST to either of the endpoints:
114
113
115
- ::
114
+ ` ` ` bash
116
115
117
- curl -X POST -d "email=aaron@email.com" localhost:8000/auth/email/
116
+ curl -X POST -d " email=aaron@email.com" localhost:8000/auth/email/
118
117
119
- curl -X POST -d "mobile=+15552143912" localhost:8000/mobile/
118
+ // OR
120
119
120
+ curl -X POST -d " mobile=+15552143912" localhost:8000/mobile/
121
+ ` ` `
121
122
A 6 digit callback token will be sent to the contact point.
122
123
123
124
6. The client has 15 minutes to use the 6 digit callback token
124
125
correctly. If successful, they get an authorization token in exchange
125
126
which the client can then use with Django Rest Framework’s
126
127
TokenAuthentication scheme.
127
128
128
- ::
129
+ ` ` ` bash
130
+ curl -X POST -d " token=815381" localhost:8000/callback/auth/
129
131
130
- curl -X POST -d "token=815381" localhost:8000/callback/auth/
131
-
132
- > HTTP/1.0 200 OK
133
- > {"token":"76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e”}
132
+ > HTTP/1.0 200 OK
133
+ > {" token" :" 76be2d9ecfaf5fa4226d722bzdd8a4fff207ed0e”}
134
+ ` ` `
134
135
135
136
Configuring Emails
136
137
------------------
@@ -144,27 +145,27 @@ development you can set up a dummy development smtp server to test
144
145
emails. Sent emails will print to the console. ` Read more
145
146
here. <https://docs.djangoproject.com/en/1.10/topics/email/#configuring-email-for-development>` __
146
147
147
- ::
148
-
148
+ ` ` ` python
149
149
# Settings.py
150
150
…
151
151
EMAIL_HOST = 'localhost'
152
152
EMAIL_PORT = 1025
153
+ ` ` `
153
154
154
155
Then run the following:
155
156
156
- ::
157
-
157
+ ` ` ` bash
158
158
python -m smtpd -n -c DebuggingServer localhost:1025
159
+ ` ` `
159
160
160
161
Configuring Mobile
161
162
------------------
162
163
163
164
You’ll need to have the python twilio module installed
164
165
165
- ::
166
-
167
- pip install twilio
166
+ ` ` ` bash
167
+ pipenv install twilio
168
+ ` ` `
168
169
169
170
and set the ` ` TWILIO_ACCOUNT_SID` ` and ` ` TWILIO_AUTH_TOKEN` ` environment
170
171
variables.
@@ -178,12 +179,12 @@ Templates
178
179
If you’d like to use a custom email template for your email callback
179
180
token, specify your template name with this setting:
180
181
181
- ::
182
-
182
+ ` ` ` bash
183
183
PASSWORDLESS_AUTH = {
184
- //…
185
- 'PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME': "mytemplate.html"
184
+ ...
185
+ 'PASSWORDLESS_EMAIL_TOKEN_HTML_TEMPLATE_NAME': " mytemplate.html"
186
186
}
187
+ ` ` `
187
188
188
189
The template renders a single variable ` ` {{ callback_token }}` ` which is
189
190
the 6 digit callback token being sent.
@@ -225,8 +226,7 @@ Other Settings
225
226
226
227
Here’s a full list of the configurable defaults.
227
228
228
- ::
229
-
229
+ ```python
230
230
DEFAULTS = {
231
231
232
232
# Allowed auth types, can be EMAIL, MOBILE, or both.
@@ -293,10 +293,42 @@ Here’s a full list of the configurable defaults.
293
293
# Automatically send verification email or sms when a user changes their alias.
294
294
' PASSWORDLESS_AUTO_SEND_VERIFICATION_TOKEN' : False,
295
295
}
296
+ ` ` `
296
297
297
- Todo
298
+ To Do
298
299
----
299
300
301
+ - github.io project page
302
+ - Add MkDocs - http://www.mkdocs.org/
300
303
- Support non-US mobile numbers
301
304
- Custom URLs
302
- - Change bad settings to 500's
305
+ - Change bad settings to 500's
306
+
307
+ Pull requests are encouraged!
308
+
309
+ License
310
+ -------
311
+
312
+ The MIT License (MIT)
313
+
314
+ Copyright (c) 2017 Aaron Ng
315
+
316
+ Permission is hereby granted, free of charge, to any person obtaining a copy
317
+ of this software and associated documentation files (the " Software" ), to deal
318
+ in the Software without restriction, including without limitation the rights
319
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
320
+ copies of the Software, and to permit persons to whom the Software is
321
+ furnished to do so, subject to the following conditions:
322
+
323
+ The above copyright notice and this permission notice shall be included in all
324
+ copies or substantial portions of the Software.
325
+
326
+ THE SOFTWARE IS PROVIDED " AS IS" , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
327
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
328
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
329
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
330
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
331
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
332
+ SOFTWARE.
333
+
334
+ [ci-image]: https://travis-ci.org/aaronn/django-rest-framework-passwordless.svg?branch=master
0 commit comments