
    '[f                         d dl mZ d dlmZ d dlmZ d dlmZmZ ddl	m
Z
mZmZmZ ddlmZ d	d
gZ G d d
ee          Z G d dee          Z G d d	ee          ZdS )    )Session)AuthBase)OAuth2Client)
ClientAuth	TokenAuth   )
OAuthErrorInvalidTokenErrorMissingTokenErrorUnsupportedTokenTypeError   )update_session_configureOAuth2Session
OAuth2Authc                       e Zd ZdZd Zd ZdS )r   zFSign requests for OAuth 2.0, currently only bearer token is supported.c                 r    | j         r-| j                             | j                  st                      d S d S N)clientensure_active_tokentokenr
   )selfs    g/var/www/piapp/venv/lib/python3.11/site-packages/authlib/integrations/requests_client/oauth2_session.pyr   zOAuth2Auth.ensure_active_token   sE    ; 	&t{>>tzJJ 	&#%%%	& 	& 	& 	&    c                    |                                   	 |                     |j        |j        |j                  \  |_        |_        |_        n4# t
          $ r'}dt          |           }t          |          d }~ww xY w|S )NzUnsupported token_type: )description)r   prepareurlheadersbodyKeyErrorstrr   )r   reqerrorr   s       r   __call__zOAuth2Auth.__call__   s      """	E-1\\ch.0 .0*CGS[#(( 	E 	E 	EASZZAAK+DDDD	E 
s   9A 
B"A<<BN)__name__
__module____qualname____doc__r   r$    r   r   r   r      s8        PP& & &    r   c                       e Zd ZdZd ZdS )OAuth2ClientAuthzFAttaches OAuth Client Authentication to the given Request object.
    c                     |                      |j        |j        |j        |j                  \  |_        |_        |_        |S r   )r   methodr   r   r   )r   r"   s     r   r$   zOAuth2ClientAuth.__call__%   s:    )-Jch*
 *
&ch 
r   N)r%   r&   r'   r(   r$   r)   r   r   r+   r+   "   s-             r   r+   c                   P     e Zd ZdZeZeZeZ	dZ
	 	 	 	 	 	 d	dZd
dZd fd	Z xZS )r   a  Construct a new OAuth 2 client requests session.

    :param client_id: Client ID, which you get from client registration.
    :param client_secret: Client Secret, which you get from registration.
    :param authorization_endpoint: URL of the authorization server's
        authorization endpoint.
    :param token_endpoint: URL of the authorization server's token endpoint.
    :param token_endpoint_auth_method: client authentication method for
        token endpoint.
    :param revocation_endpoint: URL of the authorization server's OAuth 2.0
        revocation endpoint.
    :param revocation_endpoint_auth_method: client authentication method for
        revocation endpoint.
    :param scope: Scope that you needed to access user resources.
    :param state: Shared secret to prevent CSRF attack.
    :param redirect_uri: Redirect URI you registered as callback.
    :param token: A dict of token attributes such as ``access_token``,
        ``token_type`` and ``expires_at``.
    :param token_placement: The place to put token in HTTP request. Available
        values: "header", "body", "uri".
    :param update_token: A function for you to update token. It accept a
        :class:`OAuth2Token` as parameter.
    :param default_timeout: If settled, every requests will have a default timeout.
    )
allow_redirectstimeoutcookiesfilesproxieshooksstreamverifycertjsonNheaderc                     t          j        |            || _        t          | |           t	          j        | f| |||||||||	|
d| d S )N)session	client_idclient_secrettoken_endpoint_auth_methodrevocation_endpoint_auth_methodscopestateredirect_urir   token_placementupdate_token)r   __init__default_timeoutr   r   )r   r<   r=   r>   r?   r@   rA   rB   r   rC   rD   rF   kwargss                r   rE   zOAuth2Session.__init__M   s     	. v...	
}'A,Ku<%	
 	
 *0	
 	
 	
 	
 	
r   c                      | j         |fi |S )zAlias for fetch_token.)fetch_token)r   r   rG   s      r   fetch_access_tokenz OAuth2Session.fetch_access_tokena   s    t..v...r   Fc                     | j         r|                    d| j                    |s|| j        st                      | j        } t                      j        ||fd|i|S )z<Send request with auto refresh token feature (if available).r0   Nauth)rF   
setdefaultr   r   
token_authsuperrequest)r   r-   r   withhold_tokenrL   rG   	__class__s         r   rP   zOAuth2Session.requeste   s     	?i)=>>> 	#$,: *')))?DuwwC. .".&,. . 	.r   )NNNNNNNNr9   NNr   )FN)r%   r&   r'   r(   r+   client_auth_classr   token_auth_classr	   oauth_error_classSESSION_REQUEST_PARAMSrE   rJ   rP   __classcell__)rR   s   @r   r   r   ,   s         0 )!"
 6:,0156:-548
 
 
 
(/ / / /	. 	. 	. 	. 	. 	. 	. 	. 	. 	.r   N)requestsr   requests.authr   authlib.oauth2.clientr   authlib.oauth2.authr   r   base_clientr	   r
   r   r   utilsr   __all__r   r+   r   r)   r   r   <module>r_      sE         " " " " " " . . . . . . 5 5 5 5 5 5 5 5            , + + + + +L
)    9   $    x   B. B. B. B. B.L' B. B. B. B. B.r   