diff --git a/src/authentic2_pratic/urls.py b/src/authentic2_pratic/urls.py index e7113b8..ad18a59 100644 --- a/src/authentic2_pratic/urls.py +++ b/src/authentic2_pratic/urls.py @@ -50,4 +50,5 @@ urlpatterns = patterns('', url('^manage/collectivities/add/$', views.collectivity_add, name='a2-pratic-collectivity-add'), url('^manage/collectivities/(?P\d+)/', include(collectivity_urlpatterns)), url('^$', views.agent_homepage, name='auth_homepage'), + url('^services.json$', views.agent_homepage_jsonp, name='auth_homepage_jsonp'), ) diff --git a/src/authentic2_pratic/views.py b/src/authentic2_pratic/views.py index 50fcbc7..38a01f1 100644 --- a/src/authentic2_pratic/views.py +++ b/src/authentic2_pratic/views.py @@ -1,5 +1,6 @@ +import json from django.utils.translation import ugettext_lazy as _ -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.contrib import messages from django.contrib.auth.views import redirect_to_login @@ -398,3 +399,22 @@ def get_service_links(request): def agent_homepage(request): ctx = {'service_links': get_service_links(request)} return render(request, 'authentic2_pratic/agent_homepage.html', ctx) + +def agent_homepage_jsonp(request): + service_links = get_service_links(request) + data = [] + for name, url, slug, needed_authent in service_links: + data.append({ + 'url': url, + 'label': name, + 'authentication_level_is_enough': not bool(needed_authent), + 'authentication_levels': filter(None, needed_authent.split(', ')), + }) + response = HttpResponse(content_type='application/json') + json_str = json.dumps(data) + for variable in ('jsonpCallback', 'callback'): + if variable in request.GET: + json_str = '%s(%s);' % (request.GET[variable], json_str) + break + response.write(json_str) + return response