From af973256dbcfbcbd4007cbfb1b571143a2ceee55 Mon Sep 17 00:00:00 2001 From: Leif Johansson Date: Mon, 7 Nov 2011 18:46:56 +0100 Subject: a simple oauth2-protected hello-world --- coip/apps/name/views.py | 7 ++++++- coip/urls.py | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'coip') diff --git a/coip/apps/name/views.py b/coip/apps/name/views.py index b50526c..e77a6ed 100644 --- a/coip/apps/name/views.py +++ b/coip/apps/name/views.py @@ -16,6 +16,7 @@ from coip.apps.name.forms import NameEditForm, NewNameForm, NameDeleteForm,\ from django.shortcuts import get_object_or_404 from django.contrib.auth.models import User from django.db.models import Q +from django_oauth2_lite.decorators import oauth2_required @login_required def delete(request,id): @@ -235,4 +236,8 @@ def search(request): if request.REQUEST.has_key('term'): term = request.REQUEST['term'] list = [{'label': name.shortname(),'value': name.id} for name in Name.objects.filter(Q(short__contains=term) | Q(value__contains=term))] - return json_response(list) \ No newline at end of file + return json_response(list) + +@oauth2_required(scope='memberships') +def hello(request): + return json_response('world') \ No newline at end of file diff --git a/coip/urls.py b/coip/urls.py index c1470e0..49df4d4 100644 --- a/coip/urls.py +++ b/coip/urls.py @@ -74,5 +74,6 @@ urlpatterns = patterns('', (r'^api/', include(v1_api.urls)), (r'^opensocial/1.0/rpc', 'coip.apps.opensocial.common.system'), (r'^opensocial/', include(opensocial_v1.urls)), - (r'^oauth2/', include('django_oauth2_lite.urls')) + (r'^hello/?', 'coip.apps.name.views.hello'), + (r'^oauth2/', include('django_oauth2_lite.urls')) ) -- cgit v1.1