o
    ^[2hs                     @   s   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 deeZG dd deeZG dd deeZdS )    )Session)AuthBase)
ClientAuth)	TokenAuth)OAuth2Client   )InvalidTokenError)MissingTokenError)
OAuthError)UnsupportedTokenTypeError   )update_session_configureOAuth2Session
OAuth2Authc                   @   s    e Zd ZdZdd Zdd ZdS )r   zFSign requests for OAuth 2.0, currently only bearer token is supported.c                 C   s"   | j r| j | jst d S d S N)clientensure_active_tokentokenr   )self r   /home/skpark/git/infrasmart_work/infrasmart/venv/lib/python3.10/site-packages/authlib/integrations/requests_client/oauth2_session.pyr      s   zOAuth2Auth.ensure_active_tokenc              
   C   sb   |    z| |j|j|j\|_|_|_W |S  ty0 } zdt| }t|d|d }~ww )NzUnsupported token_type: )description)r   prepareurlheadersbodyKeyErrorstrr   )r   reqerrorr   r   r   r   __call__   s   zOAuth2Auth.__call__N)__name__
__module____qualname____doc__r   r    r   r   r   r   r      s    c                   @   s   e Zd ZdZdd ZdS )OAuth2ClientAuthzAAttaches OAuth Client Authentication to the given Request object.c                 C   s(   |  |j|j|j|j\|_|_|_|S r   )r   methodr   r   r   )r   r   r   r   r   r    '   s   zOAuth2ClientAuth.__call__N)r!   r"   r#   r$   r    r   r   r   r   r%   $   s    r%   c                       s^   e Zd ZdZeZeZeZ	dZ
												dddZddd	Zd fdd	Z  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jsonNheader<   c                 K   sJ   t |  || _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leeway)r   __init__default_timeoutr   r   )r   r4   r5   r6   r7   r8   r9   r:   r   r;   r<   r=   r?   kwargsr   r   r   r>   [   s*   


zOAuth2Session.__init__c                 K   s   | j |fi |S )zAlias for fetch_token.)fetch_token)r   r   r@   r   r   r   fetch_access_token   s   z OAuth2Session.fetch_access_tokenFc                    sL   | j r
|d| j  |s|du r| jst | j}t j||fd|i|S )z<Send request with auto refresh token feature (if available).r(   Nauth)r?   
setdefaultr   r	   
token_authsuperrequest)r   r&   r   withhold_tokenrC   r@   	__class__r   r   rG      s   zOAuth2Session.request)NNNNNNNNr1   Nr2   Nr   )FN)r!   r"   r#   r$   r%   client_auth_classr   token_auth_classr
   oauth_error_classSESSION_REQUEST_PARAMSr>   rB   rG   __classcell__r   r   rI   r   r   .   s*    

%N)requestsr   requests.authr   authlib.oauth2.authr   r   authlib.oauth2.clientr   base_clientr   r	   r
   r   utilsr   __all__r   r%   r   r   r   r   r   <module>   s    
