def createIdpResponse(self, authn_request_id='2aaaeb7692471eb4ba00d5546877a7fd'): from saml2.saml import Issuer, Assertion from saml2.saml import Subject, NameID, SubjectConfirmation, SubjectConfirmationData from saml2.saml import Conditions, AudienceRestriction, Audience, OneTimeUse from saml2.saml import AuthnStatement, AuthnContext, AuthnContextClassRef from saml2.saml import NAMEID_FORMAT_UNSPECIFIED, SUBJECT_CONFIRMATION_METHOD_BEARER from saml2.saml import NAMEID_FORMAT_ENTITY from saml2.samlp import Response, Status, StatusCode from saml2.samlp import STATUS_SUCCESS from saml2.utils import make_instance from saml2.sigver import pre_signature_part from xmldsig import Signature issue_instant = datetime.utcnow().isoformat() + 'Z' not_before = (datetime.utcnow() - timedelta(minutes=5)).isoformat() + 'Z' not_on_or_after = (datetime.utcnow() + timedelta(minutes=5)).isoformat() + 'Z' issuer = Issuer(format=NAMEID_FORMAT_ENTITY, text='https://idp.swisssign.net/suisseid/eidp') signature = make_instance(Signature, pre_signature_part('_ea7f4526-43a3-42d6-a0bc-8f367e95802f')) status = Status(status_code=StatusCode(value=STATUS_SUCCESS)) subject_confirmation_data = SubjectConfirmationData(not_on_or_after=not_on_or_after, in_response_to=authn_request_id, recipient='http://nohost/') subject_confirmation = SubjectConfirmation(method=SUBJECT_CONFIRMATION_METHOD_BEARER, subject_confirmation_data=subject_confirmation_data) subject = Subject(name_id=NameID(text='1234-1234-1234-1234', format=NAMEID_FORMAT_UNSPECIFIED), subject_confirmation=subject_confirmation) conditions = Conditions(not_before=not_before, not_on_or_after=not_on_or_after, audience_restriction=AudienceRestriction(Audience('http://nohost/')), one_time_use=OneTimeUse()) authn_context = AuthnContext(authn_context_decl_ref=AuthnContextClassRef('urn:oasis:names:tc:SAML:2.0:ac:classes:SmartcardPKI')) authn_statement = AuthnStatement(authn_instant=issue_instant, authn_context=authn_context) assertion_signature = make_instance(Signature, pre_signature_part('_cb8e7dc8-00b3-4655-ad2d-d083cae5168d')) assertion = Assertion(id='_cb8e7dc8-00b3-4655-ad2d-d083cae5168d', version='2.0', issue_instant=issue_instant, issuer=issuer, signature=assertion_signature, subject=subject, conditions=conditions, authn_statement=authn_statement, ) response = Response(id='_ea7f4526-43a3-42d6-a0bc-8f367e95802f', in_response_to=authn_request_id, version='2.0', issue_instant=issue_instant, destination='http://nohost/', issuer=issuer, signature=signature, status=status, assertion=assertion, ) return response