from urlparse import urljoin
from werkzeug.exceptions import Forbidden, NotFound
+from oauthlib.oauth1 import ResourceEndpoint
from mediagoblin import mg_globals as mgg
from mediagoblin import messages
return wrapper
-def oauth_requeired(controller):
+def oauth_required(controller):
""" Used to wrap API endpoints where oauth is required """
@wraps(controller)
def wrapper(request, *args, **kwargs):
error = "Missing required parameter."
return json_response({"error": error}, status=400)
-
-
+
+ request_validator = GMGRequestValidator()
+ resource_endpoint = ResourceEndpoint(request_validator)
+ valid, request = resource_endpoint.validate_protected_resource_request(
+ uri=request.url,
+ http_method=request.method,
+ body=request.get_data(),
+ headers=dict(request.headers),
+ )
+ #print "[VALID] %s" % valid
+ #print "[REQUEST] %s" % request
+
+ return controller(request, *args, **kwargs)
+
+ return wrapper
from oauthlib.oauth1 import (AuthorizationEndpoint, RequestValidator,
RequestTokenEndpoint, AccessTokenEndpoint)
-from mediagoblin.decorators import require_active_login
+from mediagoblin.decorators import require_active_login, oauth_required
from mediagoblin.tools.translate import pass_to_ugettext
from mediagoblin.meddleware.csrf import csrf_exempt
from mediagoblin.tools.request import decode_request
av = AccessTokenEndpoint(request_validator)
tokens = av.create_access_token(request, {})
return form_response(tokens)
-
+
+@csrf_exempt
+@oauth_required
+def test(request):
+ return json_response({"check":"OK"})