
    ~h                         d Z ddlZddlmZ ddlmZ  ej                  e      ZdgZ	 G d d      Z
d Zd	 Zd
 ZddZy)a  authlib.oauth2.rfc6749.authenticate_client.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Registry of client authentication methods, with 3 built-in methods:

1. client_secret_basic
2. client_secret_post
3. none

The "client_secret_basic" method is used a lot in examples of `RFC6749`_,
but the concept of naming are introduced in `RFC7591`_.

.. _`RFC6749`: https://tools.ietf.org/html/rfc6749
.. _`RFC7591`: https://tools.ietf.org/html/rfc7591
    N   InvalidClientError)extract_basic_authorizationClientAuthenticationc                   &    e Zd Zd Zd Zd ZddZy)r   c                 @    || _         t        t        t        d| _        y )N)noneclient_secret_basicclient_secret_post)query_clientauthenticate_none authenticate_client_secret_basicauthenticate_client_secret_post_methods)selfr   s     f/opt/mcp/mcp-sentiment/venv/lib/python3.12/site-packages/authlib/oauth2/rfc6749/authenticate_client.py__init__zClientAuthentication.__init__   s    (%#C"A
    c                 "    || j                   |<   y N)r   )r   methodfuncs      r   registerzClientAuthentication.register$   s     $fr   c                     |D ]D  }| j                   |   } || j                  |      }|s(|j                  ||      s;||_        |c S  d|v rt	        dd|       t	        d|       )Nr     z-The client cannot authenticate with methods: status_codedescription)r   )r   r   check_endpoint_auth_methodauth_methodr   )r   requestmethodsendpointr   r   clients          r   authenticatez!ClientAuthentication.authenticate'   s     	F==(D$++W5F&;;FHM&,#	 !G+$KG9U  !GyQ
 	
r   c                 (    | j                  |||      S r   )r&   )r   r"   r#   r$   s       r   __call__zClientAuthentication.__call__8   s      '8<<r   N)token)__name__
__module____qualname__r   r   r&   r(    r   r   r   r      s    
%
"=r   c                     t        |j                        \  }}|r;|r9t        | |d      }|j                  |      rt        j                  d| d       |S t        j                  d| d       y)znAuthenticate client by ``client_secret_basic`` method. The client
    uses HTTP Basic for authentication.
    r   Authenticate z" via "client_secret_basic" successz! via "client_secret_basic" failedN)r   headers_validate_clientcheck_client_secretlogdebug)r   r"   	client_idclient_secretr%   s        r   r   r   <   si      ;7??KI}]!,	3?%%m4IIi[0RSTMIIi[(IJKr   c                 
   |j                   }|j                  d      }|j                  d      }|r:|r8t        | |      }|j                  |      rt        j                  d| d       |S t        j                  d| d       y)zrAuthenticate client by ``client_secret_post`` method. The client
    uses POST parameters for authentication.
    r5   r6   r/   z! via "client_secret_post" successz  via "client_secret_post" failedN)formgetr1   r2   r3   r4   )r   r"   datar5   r6   r%   s         r   r   r   I   sy     <<D%IHH_-M]!,	:%%m4IIi[0QRSMIIi[(HIJr   c                     |j                   j                  }|rL|j                   j                  j                  d      s't	        | |      }t
        j                  d| d       |S t
        j                  d| d       y)zaAuthenticate public client by ``none`` method. The client
    does not have a client secret.
    r6   r/   z via "none" successz via "none" failedN)payloadr5   r:   r9   r1   r3   r4   )r   r"   r5   r%   s       r   r   r   X   sj     ))I--11/B!,	:		M),?@AIIi[(:;<r   c                 R    |t        |d       | |      }|st        |d      |S )NzMissing 'client_id' parameter.r   z)The client does not exist on this server.r   )r   r5   r   r%   s       r   r1   r1   d   sD     #8
 	

 )$F #C
 	

 Mr   )i  )__doc__loggingerrorsr   utilr   	getLoggerr*   r3   __all__r   r   r   r   r1   r-   r   r   <module>rD      sP      & -g!!
"= =B
LK	=r   