aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/oauth/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/plugins/oauth/views.py')
-rw-r--r--mediagoblin/plugins/oauth/views.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/mediagoblin/plugins/oauth/views.py b/mediagoblin/plugins/oauth/views.py
index cf605fd2..c7b2a332 100644
--- a/mediagoblin/plugins/oauth/views.py
+++ b/mediagoblin/plugins/oauth/views.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
# GNU MediaGoblin -- federated, autonomous media hosting
# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
#
@@ -17,7 +18,6 @@
import logging
import json
-from webob import exc, Response
from urllib import urlencode
from uuid import uuid4
from datetime import datetime
@@ -94,7 +94,7 @@ def authorize_client(request):
if not client:
_log.error('''No such client id as received from client authorization
form.''')
- return exc.HTTPBadRequest()
+ return BadRequest()
if form.validate():
relation = OAuthUserClient()
@@ -105,11 +105,11 @@ def authorize_client(request):
elif form.deny.data:
relation.state = u'rejected'
else:
- return exc.HTTPBadRequest
+ return BadRequest
relation.save()
- return exc.HTTPFound(location=form.next.data)
+ return redirect(request, location=form.next.data)
return render_to_response(
request,
@@ -162,7 +162,7 @@ def authorize(request, client):
_log.debug('Redirecting to {0}'.format(redirect_uri))
- return exc.HTTPFound(location=redirect_uri)
+ return redirect(request, location=redirect_uri)
else:
# Show prompt to allow client to access data
# - on accept: send the user agent back to the redirect_uri with the
@@ -216,12 +216,15 @@ def access_token(request):
token.client = code.client
token.save()
+ # expire time of token in full seconds
+ # timedelta.total_seconds is python >= 2.7 or we would use that
+ td = token.expires - datetime.now()
+ exp_in = 86400*td.days + td.seconds # just ignore µsec
+
access_token_data = {
'access_token': token.token,
'token_type': 'bearer',
- 'expires_in': int(
- round(
- (token.expires - datetime.now()).total_seconds()))}
+ 'expires_in': exp_in}
return json_response(access_token_data, _disable_cors=True)
else:
return json_response({