auth_saml: allow custom template for each idp login block (#39154)

This commit is contained in:
Serghei Mihai 2020-01-21 16:42:37 +01:00
parent 8f15b83906
commit ba597c14d5
3 changed files with 19 additions and 3 deletions

View File

@ -35,7 +35,7 @@ class SAMLAuthenticator(object):
def instances(self, request, *args, **kwargs):
for idx, idp in enumerate(get_idps()):
yield(idx, idp)
yield(idp.get('SLUG') or idx, idp)
def login(self, request, *args, **kwargs):
context = kwargs.pop('context', {})
@ -46,7 +46,8 @@ class SAMLAuthenticator(object):
instance = kwargs.get('instance')
return redirect_to_login(request, login_url='mellon_login',
params={'entityID': instance['ENTITY_ID']})
return render(request, 'authentic2_auth_saml/login.html', context)
return render(request, ['authentic2_auth_saml/login_%s.html' % instance_id,
'authentic2_auth_saml/login.html'], context)
def profile(self, request, *args, **kwargs):
context = kwargs.pop('context', {})

View File

@ -1,5 +1,8 @@
{% load i18n %}
{% block before-login %}
{% endblock %}
{% block login %}
<form method="post">
<button class="submit-button" name="{{ submit_name }}">{% trans "Login" %}</button>
@ -8,3 +11,6 @@
{% endif %}
</form>
{% endblock %}
{% block after-login %}
{% endblock %}

View File

@ -34,10 +34,19 @@ def test_providers_on_login_page(db, app, settings):
assert response.pyquery('button[name="login-saml-0"]')
assert not response.pyquery('button[name="login-saml-1"]')
PROVIDERS = [
{'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1', 'SLUG': 'idp1'},
]
settings.MELLON_IDENTITY_PROVIDERS = PROVIDERS
response = app.get('/login/')
assert response.pyquery('button[name="login-saml-idp1"]')
assert not response.pyquery('button[name="login-saml-1"]')
PROVIDERS.append({'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1'})
response = app.get('/login/')
# two frontends should be present on login page
assert response.pyquery('button[name="login-saml-0"]')
assert response.pyquery('button[name="login-saml-idp1"]')
assert response.pyquery('button[name="login-saml-1"]')