Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
5a3874ee
Commit
5a3874ee
authored
Sep 07, 2012
by
Mjumbe Wawatu Poe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create a key by default if none is specified
parent
f3e65eab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
1 deletions
+12
-1
djangorestframework/tests/authentication.py
+5
-0
djangorestframework/tokenauth/models.py
+7
-1
djangorestframework/tokenauth/views.py
+0
-0
No files found.
djangorestframework/tests/authentication.py
View file @
5a3874ee
...
@@ -146,3 +146,8 @@ class TokenAuthTests(TestCase):
...
@@ -146,3 +146,8 @@ class TokenAuthTests(TestCase):
"""Ensure POSTing json over token auth without correct credentials fails"""
"""Ensure POSTing json over token auth without correct credentials fails"""
response
=
self
.
csrf_client
.
post
(
'/'
,
json
.
dumps
({
'example'
:
'example'
}),
'application/json'
)
response
=
self
.
csrf_client
.
post
(
'/'
,
json
.
dumps
({
'example'
:
'example'
}),
'application/json'
)
self
.
assertEqual
(
response
.
status_code
,
403
)
self
.
assertEqual
(
response
.
status_code
,
403
)
def
test_token_has_auto_assigned_key_if_none_provided
(
self
):
"""Ensure creating a token with no key will auto-assign a key"""
token
=
Token
.
objects
.
create
(
user
=
self
.
user
)
self
.
assertEqual
(
len
(
token
.
key
),
32
)
djangorestframework/tokenauth/models.py
View file @
5a3874ee
import
uuid
from
django.db
import
models
from
django.db
import
models
class
BaseToken
(
models
.
Model
):
class
BaseToken
(
models
.
Model
):
"""
"""
The base abstract authorization token model class.
The base abstract authorization token model class.
"""
"""
key
=
models
.
CharField
(
max_length
=
32
,
primary_key
=
True
)
key
=
models
.
CharField
(
max_length
=
32
,
primary_key
=
True
,
blank
=
True
)
user
=
models
.
ForeignKey
(
'auth.User'
)
user
=
models
.
ForeignKey
(
'auth.User'
)
revoked
=
models
.
BooleanField
(
default
=
False
)
revoked
=
models
.
BooleanField
(
default
=
False
)
class
Meta
:
class
Meta
:
abstract
=
True
abstract
=
True
def
save
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
key
:
self
.
key
=
uuid
.
uuid4
()
.
hex
return
super
(
BaseToken
,
self
)
.
save
(
*
args
,
**
kwargs
)
class
Token
(
BaseToken
):
class
Token
(
BaseToken
):
"""
"""
...
...
djangorestframework/tokenauth/views.py
0 → 100644
View file @
5a3874ee
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment