o
    Df                     @   s   d dl Z d dlmZ d dlmZmZ d dlmZmZ ddl	m
Z
 ddlmZ dd	 Zd
d Zdd ZG dd dZG dd dZdS )    N)quote)add_params_to_qsadd_params_to_uri)to_bytes	to_native   )OAuth2Token)add_bearer_tokenc                 C   sF   t | j dt | j }ttt|d}d| |d< |||fS )N:latin1zBasic Authorization)r   	client_idclient_secretr   base64	b64encoder   )clientmethoduriheadersbodytextauth r   L/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/oauth2/auth.pyencode_client_secret_basic	   s   
r   c                 C   sD   t |pdd| jfd| jpdfg}d|v rtt||d< |||fS )N r   r   Content-Length)r   r   r   strlenr   r   r   r   r   r   r   r   encode_client_secret_post   s   
r    c                 C   sX   |dkrt |d| jfg}|||fS t|d| jfg}d|v r'tt||d< |||fS )NGETr   r   )r   r   r   r   r   r   r   r   r   encode_none   s   

r"   c                   @   s.   e Zd ZdZeeedZdddZdd Z	dS )	
ClientAutha  Attaches OAuth Client Information to HTTP requests.

    :param client_id: Client ID, which you get from client registration.
    :param client_secret: Client Secret, which you get from registration.
    :param auth_method: Client auth method for token endpoint. The supported
        methods for now:

        * client_secret_basic (default)
        * client_secret_post
        * none
    )client_secret_basicclient_secret_postnoneNc                 C   s6   |d u rd}|| _ || _|| jv r| j| }|| _d S )Nr$   )r   r   DEFAULT_AUTH_METHODSauth_method)selfr   r   r(   r   r   r   __init__6   s   


zClientAuth.__init__c                 C   s   |  | ||||S N)r(   )r)   r   r   r   r   r   r   r   prepareB   s   zClientAuth.preparer+   )
__name__
__module____qualname____doc__r   r    r"   r'   r*   r,   r   r   r   r   r#   $   s    
r#   c                   @   s6   e Zd ZdZdZdeiZdddZdd Zd	d
 Z	dS )	TokenAutha  Attach token information to HTTP requests.

    :param token: A dict or OAuth2Token instance of an OAuth 2.0 token
    :param token_placement: The placement of the token, default is ``header``,
        available choices:

        * header (default)
        * body
        * uri
    bearerheaderNc                 C   s$   t || _|| _|| _t | _d S r+   )r   	from_dicttokentoken_placementr   sethooks)r)   r5   r6   r   r   r   r   r*   V   s   zTokenAuth.__init__c                 C   s   t || _d S r+   )r   r4   r5   )r)   r5   r   r   r   	set_token\   s   zTokenAuth.set_tokenc                 C   sd   | j d| j}| j|  }|| j d |||| j\}}}| jD ]}||||\}}}q!|||fS )N
token_typeaccess_token)r5   getDEFAULT_TOKEN_TYPESIGN_METHODSlowerr6   r8   )r)   r   r   r   r:   signhookr   r   r   r,   _   s   


zTokenAuth.prepare)r3   N)
r-   r.   r/   r0   r=   r	   r>   r*   r9   r,   r   r   r   r   r1   F   s    

r1   )r   urllib.parser   authlib.common.urlsr   r   authlib.common.encodingr   r   rfc6749r   rfc6750r	   r   r    r"   r#   r1   r   r   r   r   <module>   s    

"