Skip to content

Commit e8a8183

Browse files
author
Erick Tryzelaar
committed
allow a SP to use the configured name_id_format
1 parent 55b376e commit e8a8183

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/saml2/client.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from saml2.samlp import STATUS_UNKNOWN_PRINCIPAL
2323
from saml2.time_util import not_on_or_after
2424
from saml2.saml import AssertionIDRef
25-
from saml2.saml import NAMEID_FORMAT_PERSISTENT
2625
from saml2.client_base import Base
2726
from saml2.client_base import LogoutError
2827
from saml2.client_base import NoServiceDefined
@@ -44,7 +43,7 @@ class Saml2Client(Base):
4443

4544
def prepare_for_authenticate(self, entityid=None, relay_state="",
4645
binding=saml2.BINDING_HTTP_REDIRECT, vorg="",
47-
nameid_format=NAMEID_FORMAT_PERSISTENT,
46+
nameid_format=None,
4847
scoping=None, consent=None, extensions=None,
4948
sign=None,
5049
response_binding=saml2.BINDING_HTTP_POST,

src/saml2/client_base.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def service_urls(self, binding=BINDING_HTTP_POST):
193193

194194
def create_authn_request(self, destination, vorg="", scoping=None,
195195
binding=saml2.BINDING_HTTP_POST,
196-
nameid_format=NAMEID_FORMAT_TRANSIENT,
196+
nameid_format=None,
197197
service_url_binding=None, message_id=0,
198198
consent=None, extensions=None, sign=None,
199199
allow_create=False, sign_prepare=False, **kwargs):
@@ -261,13 +261,19 @@ def create_authn_request(self, destination, vorg="", scoping=None,
261261
else:
262262
allow_create = "false"
263263

264-
# Profile stuff, should be configurable
265-
if nameid_format is None:
266-
name_id_policy = samlp.NameIDPolicy(
267-
allow_create=allow_create, format=NAMEID_FORMAT_TRANSIENT)
268-
elif nameid_format == "":
264+
if nameid_format == "":
269265
name_id_policy = None
270266
else:
267+
if nameid_format is None:
268+
nameid_format = self.config.getattr("name_id_format", "sp")
269+
270+
if nameid_format is None:
271+
nameid_format = NAMEID_FORMAT_TRANSIENT
272+
elif isinstance(nameid_format, list):
273+
# NameIDPolicy can only have one format specified
274+
nameid_format = nameid_format[0]
275+
276+
271277
name_id_policy = samlp.NameIDPolicy(allow_create=allow_create,
272278
format=nameid_format)
273279

0 commit comments

Comments
 (0)