Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

Commit 3d9fde8

Browse files
committed
Merge pull request #10 from edx/expires-fix
Updated Access Token Detail View
2 parents 4c7658e + 9fef2d0 commit 3d9fde8

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

provider/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.7-fork-edx-4"
1+
__version__ = "0.2.7-fork-edx-5"

provider/oauth2/tests.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from django.utils.html import escape
99
from django.test import TestCase
1010
from django.contrib.auth.models import User
11-
import mock
1211

1312
from .. import constants, scope
13+
1414
from ..compat import skipIfCustomUser
15-
from provider.constants import CONFIDENTIAL, READ
1615
from ..templatetags.scope import scopes
1716
from ..utils import now as date_now
1817
from .forms import ClientForm
@@ -627,7 +626,7 @@ class AccessTokenDetailViewTests(TestCase):
627626
def setUp(self):
628627
super(AccessTokenDetailViewTests, self)
629628
self.user = User.objects.create_user('TEST-USER', '[email protected]')
630-
self.oauth_client = Client.objects.create(client_type=CONFIDENTIAL)
629+
self.oauth_client = Client.objects.create(client_type=constants.CONFIDENTIAL)
631630

632631
def assert_invalid_token_response(self, token):
633632
""" Verifies that the view returns an invalid token response for the specified token. """
@@ -653,22 +652,18 @@ def test_invalid_token(self):
653652
def test_valid_token(self):
654653
""" If the token is valid, details about the token should be returned. """
655654

656-
expires = datetime.datetime(2016, 1, 1, 0, 0, 0)
657-
access_token = AccessToken.objects.create(user=self.user, client=self.oauth_client, scope=READ, expires=expires)
655+
access_token = AccessToken.objects.create(user=self.user, client=self.oauth_client, scope=constants.READ,
656+
expires=datetime.datetime(2016, 1, 1, 0, 0, 0))
658657

659658
url = reverse('oauth2:access_token_detail', kwargs={'token': access_token.token})
660659

661-
# Mock datetime.datetime.now() so that we can validate the expiration date
662-
now = datetime.datetime(2015, 1, 1, 0, 0, 0)
663-
with mock.patch('provider.oauth2.models.now', return_value=now):
664-
response = self.client.get(url)
665-
660+
response = self.client.get(url)
666661
self.assertEqual(response.status_code, 200)
667662
self.assertEqual(response['Content-Type'], self.JSON_CONTENT_TYPE)
668663

669664
expected = {
670665
'username': self.user.username,
671666
'scope': 'read',
672-
'expires_in': int((expires - now).total_seconds())
667+
'expires': '2016-01-01T00:00:00'
673668
}
674669
self.assertEqual(response.content, json.dumps(expected))

provider/oauth2/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@ class AccessTokenDetailView(View):
151151
"""
152152
This view returns info about a given access token. If the token does not exist or is expired, HTTP 400 is returned.
153153
154-
A successful response has HTTP status 200 and includes a JSON object containing the username, scope, and expiry
155-
time (in seconds) for the access token.
154+
A successful response has HTTP status 200 and includes a JSON object containing the username, scope, and expiration
155+
date-time (in ISO 8601 format, UTC timezone) for the access token.
156156
157157
Example
158158
GET /access_token/abc123/
159159
160160
{
161161
username: "some-user",
162162
scope: "read",
163-
expires_in: 60
163+
expires: "2015-04-01T08:41:51"
164164
}
165165
"""
166166

@@ -172,7 +172,7 @@ def get(self, request, *args, **kwargs):
172172
content = {
173173
'username': access_token.user.username,
174174
'scope': access_token.get_scope_display(),
175-
'expires_in': access_token.get_expire_delta()
175+
'expires': access_token.expires.isoformat()
176176
}
177177
return HttpResponse(json.dumps(content), content_type=JSON_CONTENT_TYPE)
178178
except ObjectDoesNotExist:

0 commit comments

Comments
 (0)