aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/plugins/api/tools.py
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2012-09-21 13:02:35 +0200
committerJoar Wandborg <git@wandborg.com>2012-09-21 13:09:42 +0200
commit88a9662be4f97da5b04a3842c8d0caa2652be355 (patch)
tree1924afd6d94f4aa6932bb88feed150e9eae9fbe3 /mediagoblin/plugins/api/tools.py
parentd4c066abf017bc7af8fa30a25248dbae9e40355d (diff)
downloadmediagoblin-88a9662be4f97da5b04a3842c8d0caa2652be355.tar.lz
mediagoblin-88a9662be4f97da5b04a3842c8d0caa2652be355.tar.xz
mediagoblin-88a9662be4f97da5b04a3842c8d0caa2652be355.zip
Added client registration caps to OAuth plugin
THE MIGRATIONS SUPPLIED WITH THIS COMMIT WILL DROP AND RE-CREATE YOUR oauth__tokens AND oauth__codes TABLES. ALL YOUR OAUTH CODES AND TOKENS WILL BE LOST. - Fixed pylint issues in db/sql/migrations. - Added __repr__ to the User model. - Added _disable_cors option to json_response. - Added crude error handling to the api.tools.api_auth decorator - Updated the OAuth README. - Added client registration, client overview, connection overview, client authorization views and templates. - Added error handling to the OAuthAuth Auth object. - Added AuthorizationForm, ClientRegistrationForm in oauth/forms. - Added migrations for OAuth, added client registration migration. - Added OAuthClient, OAuthUserClient models. - Added oauth/tools with require_client_auth decorator method.
Diffstat (limited to 'mediagoblin/plugins/api/tools.py')
-rw-r--r--mediagoblin/plugins/api/tools.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/mediagoblin/plugins/api/tools.py b/mediagoblin/plugins/api/tools.py
index c4630ba7..ecc50364 100644
--- a/mediagoblin/plugins/api/tools.py
+++ b/mediagoblin/plugins/api/tools.py
@@ -52,7 +52,7 @@ class Auth(object):
raise NotImplemented()
-def json_response(serializable, *args, **kw):
+def json_response(serializable, _disable_cors=False, *args, **kw):
'''
Serializes a json objects and returns a webob.Response object with the
serialized value as the response body and Content-Type: application/json.
@@ -64,11 +64,14 @@ def json_response(serializable, *args, **kw):
'''
response = Response(json.dumps(serializable), *args, **kw)
response.headers['Content-Type'] = 'application/json'
- cors_headers = {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'}
- response.headers.update(cors_headers)
+
+ if not _disable_cors:
+ cors_headers = {
+ 'Access-Control-Allow-Origin': '*',
+ 'Access-Control-Allow-Methods': 'POST, GET, OPTIONS',
+ 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With'}
+ response.headers.update(cors_headers)
+
return response
@@ -149,6 +152,11 @@ def api_auth(controller):
auth, request.url))
if not auth(request, *args, **kw):
+ if getattr(auth, 'errors', []):
+ return json_response({
+ 'status': 403,
+ 'errors': auth.errors})
+
return exc.HTTPForbidden()
return controller(request, *args, **kw)