Skip to content

Commit

Permalink
fix: patch for atuhn request without acs url
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Mar 25, 2021
1 parent ce947c0 commit 44dc37c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/spid_sp_test/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def __init__(self, *args, **kwargs):
self.template_path)

self.metadata_etree = kwargs.get('metadata_etree')
self.acs_url = self.metadata_etree.xpath('//SPSSODescriptor/AssertionConsumerService[@index=0]'
)[0].attrib['Location']

self.authn_request_url = kwargs.get('authn_request_url')
self.authn_request_data = {}

Expand Down Expand Up @@ -153,7 +156,7 @@ def do_authnrequest(self):
'AuthnRequestID': self.authnreq_attrs['ID'],
'IssueInstant': self.authnreq_attrs['IssueInstant'],
'NotOnOrAfter': (now + datetime.timedelta(minutes=5)).strftime('%Y-%m-%dT%H:%M:%SZ'),
'AssertionConsumerURL': self.authnreq_attrs['AssertionConsumerServiceURL'],
'AssertionConsumerURL': self.authnreq_attrs.get('AssertionConsumerURL', self.acs_url),
'NameIDNameQualifier': settings.DEFAULT_RESPONSE['NameIDNameQualifier'],
'NameID': 'that-transient-opaque-value',
'AssertionID': saml_rnd_id(),
Expand Down Expand Up @@ -278,7 +281,7 @@ def send_response(self, xmlstr):
"RelayState": self.authn_request_data.get('RelayState', '/'),
"SAMLResponse": base64.b64encode(xmlstr.encode())
}
url = self.authnreq_attrs['AssertionConsumerServiceURL']
url = self.authnreq_attrs.get('AssertionConsumerURL', self.acs_url)
ua = self.authn_request_data['requests_session']
res = ua.post(url, data=data, allow_redirects=True)
msg = f'Response http status code [{res.status_code}]: {res.content.decode()}'
Expand Down

0 comments on commit 44dc37c

Please sign in to comment.