
    #	h                     x    S SK r S SKJrJr  S SKrSSKJr  SSKJr  \R                  " \	5      r
S rS rS rS	 rg)
    N)datetime	timedelta   )Mex)parse_responsec                    U(       d  [        S5      eUc-  SU;   a  [        R                  nOSU;   a  [        R                  nU[        R                  [        R                  4;  a  [        SU-  5      e[	        XX#U5      nUR
                  " U4USUS.S.UD6nUR                  S:  a   [        R                  S	UR                  5        [        UR                  5      $ )
Nz)WsTrust endpoint address can not be emptyz/trust/2005/usernamemixedz/trust/13/usernamemixedzZUnsupported soap action: %s. Contact your administrator to check your ADFS's MEX settings.z#application/soap+xml; charset=utf-8)zContent-type
SOAPAction)dataheadersi  z)Unsuccessful WsTrust request receives: %s)
ValueErrorr   ACTION_2005	ACTION_13
_build_rstpoststatus_codeloggerdebugtextr   )	usernamepasswordcloud_audience_urnendpoint_addresssoap_actionhttp_clientkwargsr
   resps	            F/var/www/html/env/lib/python3.13/site-packages/msal/wstrust_request.pysend_requestr   %   s     DEE&*:://K&*::--K3==#//:: LNYZ [ 	[.+OD, 4@%B  D 3@$))L $))$$    c                     U R                  SS5      R                  SS5      R                  SS5      R                  SS5      R                  S	S
5      $ )N&z&amp;"z&quot;'z&apos;<z&lt;>z&gt;)replace)r   s    r   escape_passwordr'   ?   sG    S'*223A	h		f	ggc624r   c                 $    U R                  S5      $ )Nz%Y-%m-%dT%H:%M:%SZ)strftime)datetime_objs    r   wsu_time_formatr+   E   s       !566r   c                    [         R                  " 5       nSR                  [        R                  S   [        R                  S   [        R                  S   U[        [        R                  " 5       5      U[        U5      [        U[        SS9-   5      U [        U5      U[        R                  :X  a  [        R                  S   O[        R                  S   UU[        R                  :X  a  S	OS
U[        R                  :X  a  SS9$ SS9$ )Na  <s:Envelope xmlns:s='{s}' xmlns:wsa='{wsa}' xmlns:wsu='{wsu}'>
        <s:Header>
            <wsa:Action s:mustUnderstand='1'>{soap_action}</wsa:Action>
            <wsa:MessageID>urn:uuid:{message_id}</wsa:MessageID>
            <wsa:ReplyTo>
            <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
            </wsa:ReplyTo>
            <wsa:To s:mustUnderstand='1'>{endpoint_address}</wsa:To>

            <wsse:Security s:mustUnderstand='1'
            xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'>
                <wsu:Timestamp wsu:Id='_0'>
                    <wsu:Created>{time_now}</wsu:Created>
                    <wsu:Expires>{time_expire}</wsu:Expires>
                </wsu:Timestamp>
                <wsse:UsernameToken wsu:Id='ADALUsernameToken'>
                    <wsse:Username>{username}</wsse:Username>
                    <wsse:Password>{password}</wsse:Password>
                </wsse:UsernameToken>
            </wsse:Security>

        </s:Header>
        <s:Body>
        <wst:RequestSecurityToken xmlns:wst='{wst}'>
        <wsp:AppliesTo xmlns:wsp='http://schemas.xmlsoap.org/ws/2004/09/policy'>
            <wsa:EndpointReference>
                <wsa:Address>{applies_to}</wsa:Address>
            </wsa:EndpointReference>
        </wsp:AppliesTo>
        <wst:KeyType>{key_type}</wst:KeyType>
            <wst:RequestType>{request_type}</wst:RequestType>
        </wst:RequestSecurityToken>
        </s:Body>
        </s:Envelope>swsuwsa10
   )minuteswstwst2005z7http://docs.oasis-open.org/ws-sx/ws-trust/200512/Bearerz9http://schemas.xmlsoap.org/ws/2005/05/identity/NoProofKeyz6http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issuez1http://schemas.xmlsoap.org/ws/2005/02/trust/Issue)r-   r.   wsar   
message_idr   time_nowtime_expirer   r   r2   
applies_tokey_typerequest_type)r   utcnowformatr   NSstruuiduuid4r+   r   r'   r   )r   r   r   r   r   nows         r   r   r   N   s    
//
C!B  ffSksvve}#&&/#DJJL0A-$S)'i.C(CD(A!,!=u366)CT)#--/ OK#--/ R   
C0
^ D   
C0
r   )r?   r   r   loggingmexr   wstrust_responser   	getLogger__name__r   r   r'   r+   r    r   r   <module>rH      s:   8  (   ,			8	$%4472
r   