o
    b                     @   s8   d dl mZ ddlmZ ddlmZ G dd deZdS )    )default_json_headers   )AccessDeniedError)InvalidTokenErrorc                   @   s   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd S )!ClientConfigurationEndpointZclient_configurationc                 C   s
   || _ d S N)server)selfr    r
   ^/var/www/secure340b-portal/env/lib/python3.10/site-packages/authlib/oauth2/rfc7592/endpoint.py__init__	      
z$ClientConfigurationEndpoint.__init__c                 C   s
   |  |S r   )create_configuration_responser	   requestr
   r
   r   __call__   r   z$ClientConfigurationEndpoint.__call__c                 C   s   |  |}|s
t ||_| |}|s| | t | ||s%t ||_|jdkr3| 	||S |jdkr>| 
||S |jdkrI| ||S d S )NGETDELETEPUT)authenticate_tokenr   Z
credentialauthenticate_clientrevoke_access_tokencheck_permissionr   clientmethodcreate_read_client_responsecreate_delete_client_responsecreate_update_client_response)r	   r   tokenr   r
   r
   r   r      s$   





z9ClientConfigurationEndpoint.create_configuration_responsec                 C   s   | j |S r   )r   Zcreate_json_requestr   r
   r
   r   create_endpoint_request,   s   z3ClientConfigurationEndpoint.create_endpoint_requestc                 C   s*   |  |}| ||}|| d|tfS )N   )introspect_client!generate_client_registration_infoupdater   )r	   r   r   bodyinfor
   r
   r   r   /   s   


z7ClientConfigurationEndpoint.create_read_client_responsec                 C   s   |  || ddg}dd|fS )a  To deprive itself on the authorization server, the client makes
        an HTTP DELETE request to the client configuration endpoint.  This
        request is authenticated by the registration access token issued to
        the client.

        The following is a non-normative example request::

            DELETE /register/s6BhdRkqt3 HTTP/1.1
            Host: server.example.com
            Authorization: Bearer reg-23410913-abewfq.123483
        )zCache-Controlzno-store)ZPragmazno-cache    )delete_client)r	   r   r   headersr
   r
   r   r   5   s
   
z9ClientConfigurationEndpoint.create_delete_client_responsec                 C   sr   d}|D ]
}||j v r dS q|j d}|s || kr d|j v r-||j d s- | ||}| ||S )a   To update a previously registered client's registration with an
        authorization server, the client makes an HTTP PUT request to the
        client configuration endpoint with a content type of "application/
        json".

        The following is a non-normative example request::

            PUT /register/s6BhdRkqt3 HTTP/1.1
            Accept: application/json
            Host: server.example.com
            Authorization: Bearer reg-23410913-abewfq.123483

            {
                "client_id": "s6BhdRkqt3",
                "client_secret": "cf136dc3c1fc93f31185e5885805d",
                "redirect_uris": [
                    "https://client.example.org/callback",
                    "https://client.example.org/alt"
                ],
                "grant_types": ["authorization_code", "refresh_token"],
                "token_endpoint_auth_method": "client_secret_basic",
                "jwks_uri": "https://client.example.org/my_public_keys.jwks",
                "client_name": "My New Example",
                "client_name#fr": "Mon Nouvel Exemple",
                "logo_uri": "https://client.example.org/newlogo.png",
                "logo_uri#fr": "https://client.example.org/fr/newlogo.png"
            }
        )Zregistration_access_tokenZregistration_client_uriZclient_secret_expires_atZclient_id_issued_atN	client_idZclient_secret)datagetZget_client_idZcheck_client_secretsave_clientr   )r	   r   r   Zmust_not_includekr*   r
   r
   r   r   H   s    

z9ClientConfigurationEndpoint.create_update_client_responsec                 C      t  )zGenerate ```registration_client_uri`` and ``registration_access_token``
        for RFC7592. This method returns ``None`` by default. Developers MAY rewrite
        this method to return registration information.NotImplementedErrorr	   r   r   r
   r
   r   r"      s   z=ClientConfigurationEndpoint.generate_client_registration_infoc                 C   r/   )aL  Authenticate current credential who is requesting to register a client.
        Developers MUST implement this method in subclass::

            def authenticate_token(self, request):
                auth = request.headers.get('Authorization')
                return get_token_by_auth(auth)

        :return: token instance
        r0   r   r
   r
   r   r         
z.ClientConfigurationEndpoint.authenticate_tokenc                 C   r/   r   r0   r   r
   r
   r   r         z/ClientConfigurationEndpoint.authenticate_clientc                 C   r/   r   r0   r   r
   r
   r   r      r4   z/ClientConfigurationEndpoint.revoke_access_tokenc                 C   r/   r   r0   r2   r
   r
   r   r      r4   z,ClientConfigurationEndpoint.check_permissionc                 C   r/   r   r0   )r	   r   r
   r
   r   r!      r4   z-ClientConfigurationEndpoint.introspect_clientc                 C   r/   )a2  Delete authorization code from database or cache. Developers MUST
        implement it in subclass, e.g.::

            def delete_client(self, client, request):
                client.delete()

        :param client: the instance of OAuth client
        :param request: formatted request instance
        r0   r2   r
   r
   r   r(      r3   z)ClientConfigurationEndpoint.delete_clientc                 C   r/   r   r0   r2   r
   r
   r   r-      r4   z'ClientConfigurationEndpoint.save_clientN)__name__
__module____qualname__ZENDPOINT_NAMEr   r   r   r   r   r   r   r"   r   r   r   r   r!   r(   r-   r
   r
   r
   r   r      s"    9r   N)Zauthlib.constsr   Zrfc6749r   Zrfc6750r   objectr   r
   r
   r
   r   <module>   s    