diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 8d6d7b7f0..f714c51d9 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -328,6 +328,7 @@ def login(request, template_name='authentic2/login.html', if hasattr(authenticator, 'instances'): for instance_id, instance in authenticator.instances(**parameters): parameters['instance'] = instance + parameters['instance_id'] = instance_id block = utils.get_authenticator_method(authenticator, 'login', parameters) # update block id in order to separate instances block['id'] = '%s_%s' % (block['id'], instance_id) diff --git a/src/authentic2_auth_saml/authenticators.py b/src/authentic2_auth_saml/authenticators.py index ebb221bae..446090cf3 100644 --- a/src/authentic2_auth_saml/authenticators.py +++ b/src/authentic2_auth_saml/authenticators.py @@ -33,12 +33,19 @@ class SAMLAuthenticator(object): def name(self): return gettext_noop('SAML') + def instances(self, request, *args, **kwargs): + for idx, idp in enumerate(get_idps()): + yield(idx, idp) + def login(self, request, *args, **kwargs): context = kwargs.pop('context', {}) - submit_name = 'login-%s' % self.id + instance_id = kwargs.get('instance_id') + submit_name = 'login-%s-%s' % (self.id, instance_id) context['submit_name'] = submit_name if request.method == 'POST' and submit_name in request.POST: - return redirect_to_login(request, login_url='mellon_login') + 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) def profile(self, request, *args, **kwargs): diff --git a/tests/test_auth_saml.py b/tests/test_auth_saml.py index 351168951..6db26539c 100644 --- a/tests/test_auth_saml.py +++ b/tests/test_auth_saml.py @@ -24,6 +24,23 @@ from django.contrib.auth import get_user_model from authentic2.models import Attribute +def test_providers_on_login_page(db, app, settings): + settings.A2_AUTH_SAML_ENABLE = True + PROVIDERS = [ + {'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1'}, + ] + settings.MELLON_IDENTITY_PROVIDERS = PROVIDERS + response = app.get('/login/') + assert response.pyquery('button[name="login-saml-0"]') + 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-1"]') + + def test_provision_attributes(db, caplog, simple_role): from authentic2_auth_saml.adapters import AuthenticAdapter