Skip to content

Commit 3c010a2

Browse files
committed
Add the ability to extract the specific certificate from IdP metadata when several defined. Use format_cert
1 parent 0c16d5c commit 3c010a2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/onelogin/saml2/idp_metadata_parser.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010
from copy import deepcopy
1111

12-
1312
try:
1413
import urllib.request as urllib2
1514
except ImportError:
1615
import urllib2
1716

1817
from onelogin.saml2.constants import OneLogin_Saml2_Constants
1918
from onelogin.saml2.xml_utils import OneLogin_Saml2_XML
19+
from onelogin.saml2.utils import OneLogin_Saml2_Utils
2020

2121

2222
class OneLogin_Saml2_IdPMetadataParser(object):
@@ -67,7 +67,9 @@ def parse_remote(url, **kwargs):
6767
def parse(
6868
idp_metadata,
6969
required_sso_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,
70-
required_slo_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT):
70+
required_slo_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,
71+
index=0
72+
):
7173
"""
7274
Parses the Identity Provider metadata and return a dict with extracted data.
7375
@@ -94,6 +96,9 @@ def parse(
9496
:type required_slo_binding: one of OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT
9597
or OneLogin_Saml2_Constants.BINDING_HTTP_POST
9698
99+
:param index: If the metadata contains more than 1 certificate, use index to get the right certificate.
100+
:type index: number
101+
97102
:returns: settings dict with extracted data
98103
:rtype: dict
99104
"""
@@ -152,8 +157,7 @@ def parse(
152157
)
153158

154159
if len(cert_nodes) > 0:
155-
# Remove leading and trailing and intermediate whitespace.
156-
idp_x509_cert = ''.join(l for l in cert_nodes[0].text.split())
160+
idp_x509_cert = OneLogin_Saml2_Utils.format_cert(cert_nodes[index].text, False)
157161

158162
data['idp'] = {}
159163

0 commit comments

Comments
 (0)