0001-auth_saml-allow-custom-template-for-each-idp-login-b.patch
src/authentic2_auth_saml/authenticators.py | ||
---|---|---|
35 | 35 | |
36 | 36 |
def instances(self, request, *args, **kwargs): |
37 | 37 |
for idx, idp in enumerate(get_idps()): |
38 |
yield(idx, idp) |
|
38 |
yield(idp.get('SLUG') or idx, idp)
|
|
39 | 39 | |
40 | 40 |
def login(self, request, *args, **kwargs): |
41 | 41 |
context = kwargs.pop('context', {}) |
... | ... | |
46 | 46 |
instance = kwargs.get('instance') |
47 | 47 |
return redirect_to_login(request, login_url='mellon_login', |
48 | 48 |
params={'entityID': instance['ENTITY_ID']}) |
49 |
return render(request, 'authentic2_auth_saml/login.html', context) |
|
49 |
return render(request, ['authentic2_auth_saml/login_%s.html' % instance_id, |
|
50 |
'authentic2_auth_saml/login.html'], context) |
|
50 | 51 | |
51 | 52 |
def profile(self, request, *args, **kwargs): |
52 | 53 |
context = kwargs.pop('context', {}) |
src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html | ||
---|---|---|
1 | 1 |
{% load i18n %} |
2 | 2 | |
3 |
{% block before-login %} |
|
4 |
{% endblock %} |
|
5 | ||
3 | 6 |
{% block login %} |
4 | 7 |
<form method="post"> |
5 | 8 |
<button class="submit-button" name="{{ submit_name }}">{% trans "Login" %}</button> |
... | ... | |
8 | 11 |
{% endif %} |
9 | 12 |
</form> |
10 | 13 |
{% endblock %} |
14 | ||
15 |
{% block after-login %} |
|
16 |
{% endblock %} |
tests/test_auth_saml.py | ||
---|---|---|
34 | 34 |
assert response.pyquery('button[name="login-saml-0"]') |
35 | 35 |
assert not response.pyquery('button[name="login-saml-1"]') |
36 | 36 | |
37 |
PROVIDERS = [ |
|
38 |
{'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1', 'SLUG': 'idp1'}, |
|
39 |
] |
|
40 |
settings.MELLON_IDENTITY_PROVIDERS = PROVIDERS |
|
41 | ||
42 |
response = app.get('/login/') |
|
43 |
assert response.pyquery('button[name="login-saml-idp1"]') |
|
44 |
assert not response.pyquery('button[name="login-saml-1"]') |
|
45 | ||
37 | 46 |
PROVIDERS.append({'METADATA': 'meta1.xml', 'ENTITY_ID': 'idp1'}) |
38 | 47 |
response = app.get('/login/') |
39 | 48 |
# two frontends should be present on login page |
40 |
assert response.pyquery('button[name="login-saml-0"]')
|
|
49 |
assert response.pyquery('button[name="login-saml-idp1"]')
|
|
41 | 50 |
assert response.pyquery('button[name="login-saml-1"]') |
42 | 51 | |
43 | 52 | |
44 |
- |