o
    +if                     @   s~   d dl Z d dlZd dlZd dlZd dlZeeZdd ZG dd de	Z
G dd de	ZG dd	 d	e
Ze
ZeZeje_dS )
    Nc                 C   s   z| j ddW S    |  Y S )Nzutf-8)encoding)encode)raw r   Q/var/www/html/corbot_env/lib/python3.10/site-packages/msal/oauth2cli/assertion.py
_str2bytes   s   r   c                   @   s&   e Zd Z		dddZ	dddZdS )	AssertionCreatorNX  c           	      K   s   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kwargsr   r   r   create_normal_assertion   s   	z(AssertionCreator.create_normal_assertionc                    s*   t |||||f fdd	t|d d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                    s    j | ||fd|i|S )Nr   )r   )aiser   r   r   r   <lambda>'   s   z@AssertionCreator.create_regenerative_assertion.<locals>.<lambda><   r   )r   )AutoRefreshermax)r   r   r   r   r   r   r   r   r   create_regenerative_assertion   s   z.AssertionCreator.create_regenerative_assertion)Nr	   NN)Nr	   )__name__
__module____qualname__r   r   r   r   r   r   r      s    
r   c                   @   s"   e Zd ZdZdddZdd ZdS )	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                 C   s   || _ || _i | _d S )N)_factory_expires_in_buf)r   factoryr   r   r   r   __init__4   s   
zAutoRefresher.__init__c                 C   s\   d\}}t   }| j|d|kr#td ||  ||| j i| _ntd | j|S )N)r   valuer   zRegenerating new assertionzReusing still valid assertion)timer%   getloggerdebugr#   r$   )r   
EXPIRES_ATVALUEnowr   r   r   __call__8   s   

zAutoRefresher.__call__N)r"   )r   r    r!   __doc__r'   r0   r   r   r   r   r   ,   s    
r   c                   @   s&   e Zd ZdddZ			dddZdS )	JwtAssertionCreatorNc                 C   s<   || _ || _|p	i | _|rtt| | jd< dS dS )a  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.
        x5tN)key	algorithmheadersbase64urlsafe_b64encodebinasciia2b_hexdecode)r   r4   r5   sha1_thumbprintr6   r   r   r   r'   D   s   
zJwtAssertionCreator.__init__r	   c
                 K   s   ddl }t }|||p||p|| |p||ptt d}|r%||d< ||	p*i  z|j|| j| j| j	d}t
|W S    | jdsM| jdrRtd  )	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)r5   r6   RSESzSome algorithms requires "pip install cryptography". See https://pyjwt.readthedocs.io/en/latest/installation.html#cryptographic-dependencies-optional)jwtr)   struuiduuid4updater   r4   r5   r6   r   
startswithr+   	exception)r   r   r   r   r   r   r   r   
not_beforeadditional_claimsr   rF   r/   payloadstr_or_bytesr   r   r   r   [   s.   	

z+JwtAssertionCreator.create_normal_assertion)NN)NNr	   NNNN)r   r    r!   r'   r   r   r   r   r   r2   C   s    
r2   )r)   r9   r7   rH   logging	getLoggerr   r+   r   objectr   r   r2   Signer	JwtSignerr   sign_assertionr   r   r   r   <module>   s    
;