From 5690e4bfab87576f0d505d56c96f87622bf8a2c1 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 27 Oct 2017 21:32:14 +1100 Subject: [PATCH] Add some niiiice h-x-app rendering to the authorisation page, so you can get a pretty view of who's trying to auth --- lemonauth/static/lemonauth/css/indie.styl | 4 ++++ lemonauth/templates/lemonauth/indie.html | 14 ++++++++++---- lemonauth/views/indie.py | 15 ++++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) create mode 100644 lemonauth/static/lemonauth/css/indie.styl diff --git a/lemonauth/static/lemonauth/css/indie.styl b/lemonauth/static/lemonauth/css/indie.styl new file mode 100644 index 0000000..ad7a699 --- /dev/null +++ b/lemonauth/static/lemonauth/css/indie.styl @@ -0,0 +1,4 @@ +.h-x-app + img + height 2em + margin-right .5em diff --git a/lemonauth/templates/lemonauth/indie.html b/lemonauth/templates/lemonauth/indie.html index ea2c089..5746b7d 100644 --- a/lemonauth/templates/lemonauth/indie.html +++ b/lemonauth/templates/lemonauth/indie.html @@ -1,12 +1,18 @@ {% extends 'lemoncurry/layout.html' %} +{% load static %} + +{% block styles %} + +{% endblock %} + {% block main %}
-

+

+ {% if app %}{% endif %} sign in to - - {{ params.client_id }} - + {% if app %}{{ app.name | first }}{% endif %} + {% if app %}({% endif %}{{ params.client_id }}{% if app %}){% endif %}?

diff --git a/lemonauth/views/indie.py b/lemonauth/views/indie.py index 7ca2e09..3bef4a5 100644 --- a/lemonauth/views/indie.py +++ b/lemonauth/views/indie.py @@ -15,9 +15,6 @@ class IndieView(TemplateView): required_params = ('me', 'client_id', 'redirect_uri') @method_decorator(login_required) - def dispatch(self, *args, **kwargs): - return super(IndieView, self).dispatch(*args, **kwargs) - def get(self, request): params = request.GET for param in self.required_params: @@ -39,15 +36,23 @@ class IndieView(TemplateView): content_type='text/plain', ) - client = mf2py.parse(url=params['client_id']) - rels = client['rel-urls'].get(params['redirect_uri'], {}).get('rels', ()) + client = mf2py.Parser(url=params['client_id'], html_parser='html5lib') + rels = (client.to_dict()['rel-urls'] + .get(params['redirect_uri'], {}) + .get('rels', ())) if 'redirect_uri' not in rels: return HttpResponseBadRequest( 'your redirect_uri is not published on your client_id page', content_type='text/plain' ) + try: + app = client.to_dict(filter_by_type='h-x-app')[0]['properties'] + except IndexError: + app = None + return render(request, self.template_name, { + 'app': app, 'params': params, 'title': 'indieauth', })