Skip to content

Commit 81e06ba

Browse files
committed
Improve AuthNRequest format
1 parent 414e05e commit 81e06ba

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/onelogin/saml2/authn_request.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def __init__(self, settings, force_authn=False, is_passive=False, set_nameid_pol
5959
else:
6060
lang = langs[0]
6161
if 'displayname' in organization_data[lang] and organization_data[lang]['displayname'] is not None:
62-
provider_name_str = 'ProviderName="%s"' % organization_data[lang]['displayname']
62+
provider_name_str = "\n" + ' ProviderName="%s"' % organization_data[lang]['displayname']
6363

6464
force_authn_str = ''
6565
if force_authn is True:
66-
force_authn_str = 'ForceAuthn="true"'
66+
force_authn_str = "\n" + ' ForceAuthn="true"'
6767

6868
is_passive_str = ''
6969
if is_passive is True:
70-
is_passive_str = 'IsPassive="true"'
70+
is_passive_str = "\n" + ' IsPassive="true"'
7171

7272
nameid_policy_str = ''
7373
if set_nameid_policy:
@@ -87,11 +87,11 @@ def __init__(self, settings, force_authn=False, is_passive=False, set_nameid_pol
8787
authn_comparison = security['requestedAuthnContextComparison']
8888

8989
if security['requestedAuthnContext'] is True:
90-
requested_authn_context_str = """ <samlp:RequestedAuthnContext Comparison="%s">
90+
requested_authn_context_str = "\n" + """ <samlp:RequestedAuthnContext Comparison="%s">
9191
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport</saml:AuthnContextClassRef>
9292
</samlp:RequestedAuthnContext>""" % authn_comparison
9393
else:
94-
requested_authn_context_str = ' <samlp:RequestedAuthnContext Comparison="%s">' % authn_comparison
94+
requested_authn_context_str = "\n" + ' <samlp:RequestedAuthnContext Comparison="%s">' % authn_comparison
9595
for authn_context in security['requestedAuthnContext']:
9696
requested_authn_context_str += '<saml:AuthnContextClassRef>%s</saml:AuthnContextClassRef>' % authn_context
9797
requested_authn_context_str += ' </samlp:RequestedAuthnContext>'
@@ -104,18 +104,13 @@ def __init__(self, settings, force_authn=False, is_passive=False, set_nameid_pol
104104
xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
105105
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
106106
ID="%(id)s"
107-
Version="2.0"
108-
%(provider_name)s
109-
%(force_authn_str)s
110-
%(is_passive_str)s
107+
Version="2.0"%(provider_name)s%(force_authn_str)s%(is_passive_str)s
111108
IssueInstant="%(issue_instant)s"
112109
Destination="%(destination)s"
113110
ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
114111
AssertionConsumerServiceURL="%(assertion_url)s"
115112
%(attr_consuming_service_str)s>
116-
<saml:Issuer>%(entity_id)s</saml:Issuer>
117-
%(nameid_policy_str)s
118-
%(requested_authn_context_str)s
113+
<saml:Issuer>%(entity_id)s</saml:Issuer>%(nameid_policy_str)s%(requested_authn_context_str)s
119114
</samlp:AuthnRequest>""" % \
120115
{
121116
'id': uid,

0 commit comments

Comments
 (0)