
    Kis                         d dl mZ d dlmZ d dlmZ d dlmZ d dlmZ ddl	m
Z
 ddl	mZ dd	l	mZ dd
l	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y)    )Session)AuthBase)
ClientAuth)	TokenAuth)OAuth2Client   )InvalidTokenError)MissingTokenError)
OAuthError)UnsupportedTokenTypeError   )update_session_configureOAuth2Session
OAuth2Authc                       e Zd ZdZd Zd Zy)r   zFSign requests for OAuth 2.0, currently only bearer token is supported.c                 |    | j                   r0| j                   j                  | j                        s
t               y y N)clientensure_active_tokentokenr	   )selfs    /home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/authlib/integrations/requests_client/oauth2_session.pyr   zOAuth2Auth.ensure_active_token   s/    ;;t{{>>tzzJ#%%  K;    c                    | j                          	 | j                  |j                  |j                  |j                        \  |_        |_        |_        |S # t
        $ r }dt        |       }t        |      |d }~ww xY w)NzUnsupported token_type: )description)r   prepareurlheadersbodyKeyErrorstrr   )r   reqerrorr   s       r   __call__zOAuth2Auth.__call__   sz      "	P-1\\chh.*CGS[#( 
  	P4SZLAK+D%O	Ps   AA 	B!A<<BN)__name__
__module____qualname____doc__r   r$    r   r   r   r      s    P&	r   c                       e Zd ZdZd Zy)OAuth2ClientAuthzAAttaches OAuth Client Authentication to the given Request object.c                     | j                  |j                  |j                  |j                  |j                        \  |_        |_        |_        |S r   )r   methodr   r   r   )r   r"   s     r   r$   zOAuth2ClientAuth.__call__'   s=    )-JJchh*
&ch 
r   N)r%   r&   r'   r(   r$   r)   r   r   r+   r+   $   s
    Kr   r+   c                   \     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 leeway: Time window in seconds before the actual expiration of the
        authentication token, that the token is considered expired and will
        be refreshed.
    :param default_timeout: If settled, every requests will have a default timeout.
    )
allow_redirectstimeoutcookiesfilesproxieshooksstreamverifycertjsonc                     t        j                  |        || _        t        | |       t	        j                  | f| |||||||||	|
|d| y )N)session	client_idclient_secrettoken_endpoint_auth_methodrevocation_endpoint_auth_methodscopestateredirect_urir   token_placementupdate_tokenleeway)r   __init__default_timeoutr   r   )r   r;   r<   r=   r>   r?   r@   rA   r   rB   rC   rD   rF   kwargss                 r   rE   zOAuth2Session.__init__[   sh      	. v.	
''A,K%+%	
 	
r   c                 (     | j                   |fi |S )zAlias for fetch_token.)fetch_token)r   r   rG   s      r   fetch_access_tokenz OAuth2Session.fetch_access_token   s    t.v..r   c                     | j                   r|j                  d| j                          |s$|"| j                  s
t               | j                  }t        |   ||fd|i|S )z<Send request with auto refresh token feature (if available).r0   auth)rF   
setdefaultr   r
   
token_authsuperrequest)r   r-   r   withhold_tokenrL   rG   	__class__s         r   rP   zOAuth2Session.request   s]    i)=)=>$,::'))??Dwvs@@@@r   )NNNNNNNNheaderN<   Nr   )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   .   sa    8 )!" #'(, #
J/A Ar   N)requestsr   requests.authr   authlib.oauth2.authr   r   authlib.oauth2.clientr   base_clientr	   r
   r   r   utilsr   __all__r   r+   r   r)   r   r   <module>ra      s[     " * ) . + + $ 3 +L
)9 &x ^AL' ^Ar   