@@ -22,7 +22,7 @@ class OneLogin_Saml2_Authn_Request(object):
2222
2323 """
2424
25- def __init__ (self , settings , force_authn = False , is_passive = False ):
25+ def __init__ (self , settings , force_authn = False , is_passive = False , set_nameid_policy = True ):
2626 """
2727 Constructs the AuthnRequest object.
2828
@@ -34,6 +34,9 @@ def __init__(self, settings, force_authn=False, is_passive=False):
3434
3535 :param is_passive: Optional argument. When true the AuthNReuqest will set the Ispassive='true'.
3636 :type is_passive: bool
37+
38+ :param set_nameid_policy: Optional argument. When true the AuthNReuqest will set a nameIdPolicy element.
39+ :type set_nameid_policy: bool
3740 """
3841 self .__settings = settings
3942
@@ -47,10 +50,6 @@ def __init__(self, settings, force_authn=False, is_passive=False):
4750
4851 destination = idp_data ['singleSignOnService' ]['url' ]
4952
50- name_id_policy_format = sp_data ['NameIDFormat' ]
51- if security ['wantNameIdEncrypted' ]:
52- name_id_policy_format = OneLogin_Saml2_Constants .NAMEID_ENCRYPTED
53-
5453 provider_name_str = ''
5554 organization_data = settings .get_organization ()
5655 if isinstance (organization_data , dict ) and organization_data :
@@ -72,6 +71,17 @@ def __init__(self, settings, force_authn=False, is_passive=False):
7271 if is_passive is True :
7372 is_passive_str = 'IsPassive="true"'
7473
74+ nameid_policy_str = ''
75+ if set_nameid_policy :
76+ name_id_policy_format = sp_data ['NameIDFormat' ]
77+ if security ['wantNameIdEncrypted' ]:
78+ name_id_policy_format = OneLogin_Saml2_Constants .NAMEID_ENCRYPTED
79+
80+ nameid_policy_str = """
81+ <samlp:NameIDPolicy
82+ Format="%s"
83+ AllowCreate="true" />""" % name_id_policy_format
84+
7585 requested_authn_context_str = ''
7686 if security ['requestedAuthnContext' ] is not False :
7787 authn_comparison = 'exact'
@@ -102,7 +112,7 @@ def __init__(self, settings, force_authn=False, is_passive=False):
102112 'destination' : destination ,
103113 'assertion_url' : sp_data ['assertionConsumerService' ]['url' ],
104114 'entity_id' : sp_data ['entityId' ],
105- 'name_id_policy ' : name_id_policy_format ,
115+ 'nameid_policy_str ' : nameid_policy_str ,
106116 'requested_authn_context_str' : requested_authn_context_str ,
107117 'attr_consuming_service_str' : attr_consuming_service_str ,
108118 }
0 commit comments