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
69e5e3cc
Commit
69e5e3cc
authored
Jun 26, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use timezone aware datetimes with oauth2 provider, when supported. Closes #947.
parent
715bd47d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
6 deletions
+18
-6
rest_framework/authentication.py
+4
-5
rest_framework/compat.py
+10
-0
rest_framework/serializers.py
+4
-1
No files found.
rest_framework/authentication.py
View file @
69e5e3cc
...
...
@@ -3,14 +3,13 @@ Provides various authentication policies.
"""
from
__future__
import
unicode_literals
import
base64
from
datetime
import
datetime
from
django.contrib.auth
import
authenticate
from
django.core.exceptions
import
ImproperlyConfigured
from
rest_framework
import
exceptions
,
HTTP_HEADER_ENCODING
from
rest_framework.compat
import
CsrfViewMiddleware
from
rest_framework.compat
import
oauth
,
oauth_provider
,
oauth_provider_store
from
rest_framework.compat
import
oauth2_provider
from
rest_framework.compat
import
oauth2_provider
,
provider_now
from
rest_framework.authtoken.models
import
Token
...
...
@@ -320,9 +319,9 @@ class OAuth2Authentication(BaseAuthentication):
try
:
token
=
oauth2_provider
.
models
.
AccessToken
.
objects
.
select_related
(
'user'
)
#
TODO: Change to timezone aware datetime when oauth2_provider add
#
support
to it.
token
=
token
.
get
(
token
=
access_token
,
expires__gt
=
datetime
.
now
())
#
provider_now switches to timezone aware datetime when
#
the oauth2_provider version supports
to it.
token
=
token
.
get
(
token
=
access_token
,
expires__gt
=
provider_
now
())
except
oauth2_provider
.
models
.
AccessToken
.
DoesNotExist
:
raise
exceptions
.
AuthenticationFailed
(
'Invalid token'
)
...
...
rest_framework/compat.py
View file @
69e5e3cc
...
...
@@ -2,6 +2,7 @@
The `compat` module provides support for backwards compatibility with older
versions of django/python, and compatibility wrappers around optional packages.
"""
# flake8: noqa
from
__future__
import
unicode_literals
...
...
@@ -489,12 +490,21 @@ try:
from
provider.oauth2
import
forms
as
oauth2_provider_forms
from
provider
import
scope
as
oauth2_provider_scope
from
provider
import
constants
as
oauth2_constants
from
provider
import
__version__
as
provider_version
if
provider_version
in
(
'0.2.3'
,
'0.2.4'
):
# 0.2.3 and 0.2.4 are supported version that do not support
# timezone aware datetimes
from
datetime.datetime
import
now
as
provider_now
else
:
# Any other supported version does use timezone aware datetimes
from
django.utils.timezone
import
now
as
provider_now
except
ImportError
:
oauth2_provider
=
None
oauth2_provider_models
=
None
oauth2_provider_forms
=
None
oauth2_provider_scope
=
None
oauth2_constants
=
None
provider_now
=
None
# Handle lazy strings
from
django.utils.functional
import
Promise
...
...
rest_framework/serializers.py
View file @
69e5e3cc
...
...
@@ -915,7 +915,10 @@ class HyperlinkedModelSerializer(ModelSerializer):
view_name
=
self
.
opts
.
view_name
,
lookup_field
=
self
.
opts
.
lookup_field
)
fields
.
insert
(
0
,
'url'
,
url_field
)
ret
=
self
.
_dict_class
()
ret
[
'url'
]
=
url_field
ret
.
update
(
fields
)
fields
=
ret
return
fields
...
...
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