o
    ©D®f±  ã                   @   s8   d dl Z ddlmZ dgZdZG dd„ dƒZdd„ ZdS )	é    Né   )ÚFrameworkIntegrationÚ	BaseOAuth)Ú	client_idÚclient_secretÚrequest_token_urlÚrequest_token_paramsÚaccess_token_urlÚaccess_token_paramsÚrefresh_token_urlÚrefresh_token_paramsÚauthorize_urlÚauthorize_paramsÚapi_base_urlÚclient_kwargsÚserver_metadata_urlc                   @   sP   e Zd ZdZdZdZeZddd„Zdd„ Z	ddd	„Z
d
d„ Zdd„ Zdd„ ZdS )r   z`Registry for oauth clients.

    Create an instance for registry::

        oauth = OAuth()
    Nc                 C   s"   i | _ i | _|| _|| _|| _d S ©N)Ú	_registryÚ_clientsÚcacheÚfetch_tokenÚupdate_token)Úselfr   r   r   © r   úb/home/ubuntu/webapp/venv/lib/python3.10/site-packages/authlib/integrations/base_client/registry.pyÚ__init__   s
   
zBaseOAuth.__init__c                 C   sØ   || j v r
| j | S || jvrdS | j| \}}| dd¡}|r,|jr,|j}| |¡ n|}| j||fi |¤Ž}|  || j¡}|rK|||fi |¤Ž}n| d¡r[| j	||fi |¤Ž}n
| j
||fi |¤Ž}|| j |< |S )a>  Create or get the given named OAuth client. For instance, the
        OAuth registry has ``.register`` a twitter client, developers may
        access the client with::

            client = oauth.create_client('twitter')

        :param: name: Name of the remote application
        :return: OAuth remote app
        NÚ
client_clsr   )r   r   ÚpopÚOAUTH_APP_CONFIGÚupdateÚgenerate_client_kwargsÚframework_integration_clsr   ÚgetÚoauth1_client_clsÚoauth2_client_cls)r   ÚnameÚ	overwriteÚconfigr   ÚkwargsÚ	frameworkÚclientr   r   r   Úcreate_client$   s&   






zBaseOAuth.create_clientFc                 K   s   ||f| j |< |  |¡S )aÛ  Registers a new remote application.

        :param name: Name of the remote application.
        :param overwrite: Overwrite existing config with framework settings.
        :param kwargs: Parameters for :class:`RemoteApp`.

        Find parameters for the given remote app class. When a remote app is
        registered, it can be accessed with *named* attribute::

            oauth.register('twitter', client_id='', ...)
            oauth.twitter.get('timeline')
        )r   r+   )r   r%   r&   r(   r   r   r   ÚregisterI   s   
zBaseOAuth.registerc                 K   s‚   |  dd ¡}|  dd ¡}|  |t¡}|rt|||ƒ}|s&| jr&t | j|¡}||d< | d¡s?|s;| jr;t | j|¡}||d< |S )Nr   r   r   )	r   Úload_configÚOAUTH_CLIENT_PARAMSÚ_config_clientr   Ú	functoolsÚpartialr"   r   )r   r%   r&   r(   r   r   r'   r   r   r   r    Y   s   


z BaseOAuth.generate_client_kwargsc                 C   s   | j  | ||¡S r   )r!   r-   )r   r%   Úparamsr   r   r   r-   m   s   zBaseOAuth.load_configc                 C   sB   zt  | |¡W S  ty    || jv r|  |¡ Y S td| ƒ‚w )NzNo such client: %s)ÚobjectÚ__getattribute__ÚAttributeErrorr   r+   )r   Úkeyr   r   r   Ú__getattr__p   s   
ýzBaseOAuth.__getattr__)NNN)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r$   r   r!   r   r+   r,   r    r-   r7   r   r   r   r   r      s    

%c                 C   sZ   t D ](}|  |d ¡}||vr|||< q|r*|r*t|| tƒr&||  |¡ q|||< q|S r   )r.   r"   Ú
isinstanceÚdictr   )r'   r(   r&   ÚkÚvr   r   r   r/   y   s   
€r/   )r0   Úframework_integrationr   Ú__all__r.   r   r/   r   r   r   r   Ú<module>   s    g