Skip to content

Commit 6d22008

Browse files
Merge pull request #431 from c00kiemon5ter/feature-force-authn-configuration
Add force_authn sp configuration option
2 parents 715a2e6 + ee17e8f commit 6d22008

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/saml2/client_base.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ def create_authn_request(self, destination, vorg="", scoping=None,
335335
except KeyError:
336336
nsprefix = None
337337

338+
try:
339+
force_authn = kwargs['force_authn']
340+
except KeyError:
341+
force_authn = self.config.getattr('force_authn', 'sp')
342+
finally:
343+
if force_authn:
344+
args['force_authn'] = 'true'
345+
338346
if kwargs:
339347
_args, extensions = self._filter_args(AuthnRequest(), extensions,
340348
**kwargs)

src/saml2/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
"name_id_format",
7676
"name_id_format_allow_create",
7777
"logout_requests_signed",
78-
"requested_attribute_name_format"
78+
"requested_attribute_name_format",
79+
"force_authn",
7980
]
8081

8182
AA_IDP_ARGS = [

tests/test_31_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
},
6969
"authn_requests_signed": True,
7070
"logout_requests_signed": True,
71+
"force_authn": True,
7172
}
7273
},
7374
#"xmlsec_binary" : "/opt/local/bin/xmlsec1",
@@ -408,5 +409,15 @@ def test_crypto_backend():
408409
sec = security_context(idpc)
409410
assert isinstance(sec.crypto, CryptoBackendXMLSecurity)
410411

412+
def test_unset_force_authn():
413+
cnf = SPConfig().load(sp1)
414+
assert bool(cnf.getattr('force_authn', 'sp')) == False
415+
416+
417+
def test_set_force_authn():
418+
cnf = SPConfig().load(sp2)
419+
assert bool(cnf.getattr('force_authn', 'sp')) == True
420+
421+
411422
if __name__ == "__main__":
412423
test_crypto_backend()

tests/test_51_client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ def test_create_auth_request_0(self):
280280
assert nid_policy.allow_create == "false"
281281
assert nid_policy.format == saml.NAMEID_FORMAT_TRANSIENT
282282

283+
def test_create_auth_request_unset_force_authn(self):
284+
req_id, req = self.client.create_authn_request(
285+
"http://www.example.com/sso", sign=False, message_id="id1")
286+
assert bool(req.force_authn) == False
287+
288+
def test_create_auth_request_set_force_authn(self):
289+
req_id, req = self.client.create_authn_request(
290+
"http://www.example.com/sso", sign=False, message_id="id1",
291+
force_authn="true")
292+
assert bool(req.force_authn) == True
293+
283294
def test_create_auth_request_nameid_policy_allow_create(self):
284295
conf = config.SPConfig()
285296
conf.load_file("sp_conf_nameidpolicy")

0 commit comments

Comments
 (0)