
    9i:                         d dl Z d dlZd dlZd dlZd dlZ ej
                  e      Zd Zd Z	 G d de
      Z G d de
      Z G d d	e      ZeZeZej                   e_        y)
    Nc                 :    	 | j                  d      S #  | cY S xY w)Nzutf-8)encoding)encode)raws    K/var/www/html/venv/lib/python3.12/site-packages/msal/oauth2cli/assertion.py
_str2bytesr      s$    zz7z++
s    c                 n    t        j                  t        j                  |             j	                         S N)base64urlsafe_b64encodebinasciia2b_hexdecode)
thumbprints    r   _encode_thumbprintr      s'    ##H$4$4Z$@AHHJJ    c                   "    e Zd Z	 	 ddZ	 ddZy)AssertionCreatorNc                     t        d      )a+  Create an assertion in bytes, based on the provided claims.

        All parameter names are defined in https://tools.ietf.org/html/rfc7521#section-5
        except the expires_in is defined here as lifetime-in-seconds,
        which will be automatically translated into expires_at in UTC.
        z Will be implemented by sub-class)NotImplementedError)	selfaudienceissuersubject
expires_at
expires_in	issued_atassertion_idkwargss	            r   create_normal_assertionz(AssertionCreator.create_normal_assertion   s     ""DEEr   c                 J     t        |||||f fd	t        |dz
  d            S )zCreate an assertion as a callable,
        which will then compute the assertion later when necessary.

        This is a useful optimization to reuse the client assertion.
        c                 2     j                   | ||fd|i|S )Nr   )r    )aiser   r   s        r   <lambda>z@AssertionCreator.create_regenerative_assertion.<locals>.<lambda>)   s&    ,,,Q1MMfM r   <   r   )r   )AutoRefreshermax)r   r   r   r   r   r   s   `     r   create_regenerative_assertionz.AssertionCreator.create_regenerative_assertion!   s1     7j N:b=!,. 	.r   )NX  NN)Nr,   )__name__
__module____qualname__r    r+    r   r   r   r      s    IL)-	F >A
.r   r   c                       e Zd ZdZddZd Zy)r)   a  Cache the output of a factory, and auto-refresh it when necessary. Usage::

        r = AutoRefresher(time.time, expires_in=5)
        for i in range(15):
            print(r())  # the timestamp change only after every 5 seconds
            time.sleep(1)
    c                 .    || _         || _        i | _        y r
   )_factory_expires_in_buf)r   factoryr   s      r   __init__zAutoRefresher.__init__6   s    %	r   c                 J   d\  }}t        j                          }| j                  j                  |d      |k  r<t        j	                  d       || j                         ||| j                  z   i| _        nt        j	                  d       | j                  j                  |      S )N)r   valuer   zRegenerating new assertionzReusing still valid assertion)timer5   getloggerdebugr3   r4   )r   
EXPIRES_ATVALUEnows       r   __call__zAutoRefresher.__call__:   s|    1
Eiik99==Q'3.LL56S4CSCS=STDILL89yy}}U##r   N)i  )r-   r.   r/   __doc__r7   rA   r0   r   r   r)   r)   .   s    $r   r)   c                   *    e Zd Z	 ddddZ	 	 	 ddZy)JwtAssertionCreatorN)sha256_thumbprintc                    || _         || _        |xs i | _        |rt        |      | j                  d<   |rt        |      | j                  d<   yy)a6  Construct a Jwt assertion creator.

        Args:

            key (str):
                An unencrypted private key for signing, in a base64 encoded string.
                It can also be a cryptography ``PrivateKey`` object,
                which is how you can work with a previously-encrypted key.
                See also https://github.com/jpadilla/pyjwt/pull/525
            algorithm (str):
                "RS256", etc.. See https://pyjwt.readthedocs.io/en/latest/algorithms.html
                RSA and ECDSA algorithms require "pip install cryptography".
            sha1_thumbprint (str): The x5t aka X.509 certificate SHA-1 thumbprint.
            headers (dict): Additional headers, e.g. "kid" or "x5c" etc.
            sha256_thumbprint (str): The x5t#S256 aka X.509 certificate SHA-256 thumbprint.
        zx5t#S256x5tN)key	algorithmheadersr   )r   rH   rI   sha1_thumbprintrJ   rE   s         r   r7   zJwtAssertionCreator.__init__F   sO    * "}"'9:K'LDLL$"4_"EDLL r   c
           	         ddl }t        j                         }|||xs ||xs ||z   |xs ||xs t        t        j                               d}|r||d<   |j                  |	xs i        	 |j                  || j                  | j                  | j                        }t        |      S #  | j                  j                  d      s| j                  j                  d      rt        j                  d        xY w)	zCreate a JWT Assertion.

        Parameters are defined in https://tools.ietf.org/html/rfc7523#section-3
        Key-value pairs in additional_claims will be added into payload as-is.
        r   N)audisssubexpiatjtinbf)rI   rJ   RSESzSome algorithms requires "pip install cryptography". See https://pyjwt.readthedocs.io/en/latest/installation.html#cryptographic-dependencies-optional)jwtr:   struuiduuid4updater   rH   rI   rJ   r   
startswithr<   	exception)r   r   r   r   r   r   r   r   
not_beforeadditional_claimsr   rV   r@   payloadstr_or_bytess                  r   r    z+JwtAssertionCreator.create_normal_assertionc   s     	iik$f3#
"2#43tzz|#4 'GEN(.B/		::T^^T\\ & SLl++	~~((.$..2K2KD2Q  wx s   -=B+ +AC9)NN)NNr,   NNNN)r-   r.   r/   r7   r    r0   r   r   rD   rD   E   s(    <@F F< OR:>"r   rD   )r:   r   r   rX   logging	getLoggerr-   r<   r   r   objectr   r)   rD   Signer	JwtSignerr    sign_assertionr0   r   r   <module>rg      ss         
		8	$K.v .2$F $.=* =B 
	.FF	 r   