
    #	h                     r     S SK Jr  S SKrSSKJr  SrSr	Sr
S	rS
 rS rS rS rg! \ a	    S SK Jr   N-f = f)    )cElementTree)ElementTreeN   )Mexz%urn:oasis:names:tc:SAML:1.0:assertionz%urn:oasis:names:tc:SAML:2.0:assertionzHhttp://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV1.1zHhttp://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#SAMLV2.0c                 n    [        U 5      nU(       a  U$ [        U 5      n[        SU=(       d    U -  5      e)Nz)WsTrust server returned error in RSTR: %s)parse_token_by_reparse_errorRuntimeError)bodytokenerrors      G/var/www/html/env/lib/python3.13/site-packages/msal/wstrust_response.pyparse_responser   ,   s3    d#EE
BemtT
UU    c                     [         R                  " U 5      nUR                  S[        R                  5      nUR                  S[        R                  5      nUc  Ub  UR
                  UR
                  S.$ g )Nzs:Body/s:Fault/s:Reason/s:Textz's:Body/s:Fault/s:Code/s:Subcode/s:Value)reasoncode)ET
fromstringfindr   NStext)r   domreason_text_nodesubcode_value_nodes       r   r	   r	   3   sf    
--
Cxx @#&&I"KSVVT#'9'E*//9K9P9PQQ (Fr   c                 Z    SSU0-  n[         R                  " X [         R                  5      $ )a<  
Given a tag name without any prefix,
this function returns a list of the raw content inside this tag as-is.

>>> findall_content("<ns0:foo> what <bar> ever </bar> content </ns0:foo>", "foo")
[" what <bar> ever </bar> content "]

Motivation:

Usually we would use XML parser to extract the data by xpath.
However the ElementTree in Python will implicitly normalize the output
by "hoisting" the inner inline namespaces into the outmost element.
The result will be a semantically equivalent XML snippet,
but not fully identical to the original one.
While this effect shouldn't become a problem in all other cases,
it does not seem to fully comply with Exclusive XML Canonicalization spec
(https://www.w3.org/TR/xml-exc-c14n/), and void the SAML token signature.
SAML signature algo needs the "XML -> C14N(XML) -> Signed(C14N(Xml))" order.

The binary extention lxml is probably the canonical way to solve this
(https://stackoverflow.com/questions/22959577/python-exclusive-xml-canonicalization-xml-exc-c14n)
but here we use this workaround, based on Regex, to return raw content as-is.
z1<(?:\w+:)?%(tag)s(?:[^>]*)>(.*)</(?:\w+:)?%(tag)stag)refindallDOTALL)
xml_stringr   patterns      r   findall_contentr#   :   s(    2 CeS\QG::g29955r   c                     [        U S5       HG  n[        US5      n[        US5      nU(       d  M$  U(       d  M-  US   R                  S5      US   S.s  $    g )NRequestSecurityTokenResponse	TokenTypeRequestedSecurityTokenr   zutf-8)r   type)r#   encode)raw_responserstrtoken_typestokenss       r   r   r   V   sW    .LM%dK8 '?@;66 $AY--g6AOO Nr   )	xml.etreer   r   ImportErrorr   r   mexr   SAML_TOKEN_TYPE_V1SAML_TOKEN_TYPE_V2WSS_SAML_TOKEN_PROFILE_V1_1WSS_SAML_TOKEN_PROFILE_V2r   r	   r#   r    r   r   <module>r6      s^   8,, 
  = <  i f VR68Pq  ,+,s   ' 66