From 0e57f9931243565d4bd15333e9f8d340698fc629 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 27 Aug 2015 14:37:44 +0200 Subject: [PATCH] views: add an iframe mode to the login view Use it by putting a tag: in your page. It will do a passive authentication inside the iframe and will use JS to reload the top frame if authentication is successfull. --- mellon/locale/fr/LC_MESSAGES/django.mo | Bin 0 -> 1135 bytes .../mellon/.authentication_failed.html.swp | Bin 0 -> 12288 bytes mellon/templates/mellon/pop_iframe.html | 8 ++++++++ mellon/views.py | 13 ++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 mellon/locale/fr/LC_MESSAGES/django.mo create mode 100644 mellon/templates/mellon/.authentication_failed.html.swp create mode 100644 mellon/templates/mellon/pop_iframe.html diff --git a/mellon/locale/fr/LC_MESSAGES/django.mo b/mellon/locale/fr/LC_MESSAGES/django.mo new file mode 100644 index 0000000000000000000000000000000000000000..e0530d5137c9fbde0e693ac1d4cf4f3fa7928ded GIT binary patch literal 1135 zcmaJ<%W4!s6fHHr#+~3o5WI*IgQ;;64aANUjCsJoObj{-ilAlpotcU~RYN_-#}7z8 zz?}=11~-0#v(cqLpeuJS{QysmiBUugPT%gXd(S;}>wG>w@ls$N0Zsw;fn&fcAgvF; z3E(4e5cmQd0=@!=fp5TB;5*O+c~R#rH$RRKJN>M|6k= z@g3p~#M2W(pj7M!c2~+zI#d6&kRp&i)+Lr==&=bpS3z4t9i>Yy#Ih~ei-z}+ooKQ5 zs>@>CQuOSoW1}hXbhNJe+*qM==M7#S=wix?c8^K@$=OqWhj*Hu*+{uEN zK>}S>)N|aap8*>`4G*F#r~H}4Qu#mww7+^$Eso2d^w@EATqo|@=*FU^AtH&J^3#MZ z?MWMz2R&pOl&m~cZcV_SMBzvkeQmT4P6g`{m)LN2lk*@Og}lSgV-^_|o62;p>~mRK zQ@P0l>w;|gt}f*D*!8k)GpcOdXv<~Ci_07abnqa%J?#=%ji0rO$EKQqT-NU*I-zWirx2XxIJgnMyT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mellon/views.py @@ -142,8 +142,16 @@ class LoginView(LogMixin, View): return render(request, 'mellon/user_not_found.html', { 'saml_attributes': attributes }) request.session['lasso_session_dump'] = login.session.dump() + iframe = login.msgRelayState.startswith('iframe+') + if iframe: + login.msgRelayState = login.msgRelayState[len('iframe+'):] next_url = login.msgRelayState or resolve_url(settings.LOGIN_REDIRECT_URL) - return HttpResponseRedirect(next_url) + if iframe: + return render(request, 'mellon/pop_iframe.html', { + 'next_url': next_url, + }) + else: + return HttpResponseRedirect(next_url) def continue_sso_artifact_get(self, request): idp_message = None @@ -210,6 +218,7 @@ class LoginView(LogMixin, View): def get(self, request, *args, **kwargs): '''Initialize login request''' + iframe = 'iframe' in request.GET if 'SAMLart' in request.GET: return self.continue_sso_artifact_get(request) next_url = request.GET.get('next') @@ -239,6 +248,8 @@ class LoginView(LogMixin, View): req_authncontext.authnContextClassRef = authn_classref if next_url: login.msgRelayState = next_url + if iframe: + login.msgRelayState = 'iframe+' + (login.msgRelayState or '') login.buildAuthnRequestMsg() except lasso.Error, e: return HttpResponseBadRequest('error initializing the '