o
    ÿÑÐb™  ã                   @   s|   d dl 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eƒZG dd„ deƒZdS )é    N)Úadd_params_to_qsÚadd_params_to_uri)Úto_bytesÚ	to_nativeé   )ÚOAuth2Token)Úadd_bearer_tokenc                 C   s<   d  | j| j¡}tt t|dƒ¡ƒ}d  |¡|d< |||fS )Nz{}:{}Úlatin1zBasic {}ÚAuthorization)ÚformatÚ	client_idÚclient_secretr   Úbase64Úurlsafe_b64encoder   )ÚclientÚmethodÚuriÚheadersÚbodyÚtextÚauth© r   úR/var/www/secure340b-portal/env/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_basicZ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__5   s   


zClientAuth.__init__c                 C   s   |   | ||||¡S ©N)r&   )r'   r   r   r   r   r   r   r   ÚprepareA   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
    ZbearerÚheaderNc                 C   s$   t  |¡| _|| _|| _tƒ | _d S r)   )r   Ú	from_dictÚtokenÚtoken_placementr   ÚsetÚhooks)r'   r2   r3   r   r   r   r   r(   U   s   zTokenAuth.__init__c                 C   s   t  |¡| _d S r)   )r   r1   r2   )r'   r2   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_typeZaccess_token)r2   ÚgetÚDEFAULT_TOKEN_TYPEÚSIGN_METHODSÚlowerr3   r5   )r'   r   r   r   r7   ÚsignÚhookr   r   r   r*   ^   s   
ý

zTokenAuth.prepare)r0   N)
r+   r,   r-   r.   r9   r   r:   r(   r6   r*   r   r   r   r   r/   E   s    
ÿ
r/   )r   Zauthlib.common.urlsr   r   Zauthlib.common.encodingr   r   Zrfc6749r   Zrfc6750r   r   r   r!   Úobjectr"   r/   r   r   r   r   Ú<module>   s    

"