o
    i)                     @   s   d dl m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lmZ d dlmZ d d	lmZmZ d d
lmZmZmZ G dd deZG dd deZeG dd dZdS )    )	dataclass)partial)AnyLiteral)	BaseModelValidationError)Request)Response)stringify_pydantic_error)PydanticJSONResponse)AuthenticationErrorClientAuthenticator)AccessToken OAuthAuthorizationServerProviderRefreshTokenc                   @   sB   e Zd ZU dZeed< dZed dB ed< eed< edB ed< dS )RevocationRequestzI
    # See https://datatracker.ietf.org/doc/html/rfc7009#section-2.1
    tokenN)Zaccess_tokenrefresh_tokentoken_type_hint	client_idZclient_secret)__name__
__module____qualname____doc__str__annotations__r   r    r   r   V/home/app/Keep/.python/lib/python3.10/site-packages/mcp/server/auth/handlers/revoke.pyr      s   
 r   c                   @   s*   e Zd ZU ed ed< dZedB ed< dS )RevocationErrorResponse)invalid_requestunauthorized_clienterrorNerror_description)r   r   r   r   r   r"   r   r   r   r   r   r      s   
 r   c                   @   s:   e Zd ZU eeeef ed< eed< dedefddZ	dS )RevocationHandlerproviderclient_authenticatorrequestreturnc           	   
      s8  z| j |I dH }W n ty) } ztdtd|jddW  Y d}~S d}~ww z| I dH }tt	|}W n t
yX } ztdtdt|ddW  Y d}~S d}~ww | jjt| jj|g}|jdkrmt|}d}|D ]}||jI dH }|dur nqq|r|j|jkr| j|I dH  td	d
dddS )zF
        Handler for the OAuth 2.0 Token Revocation endpoint.
        Ni  r    )r!   r"   )status_codecontenti  r   r      zno-storezno-cache)zCache-ControlZPragma)r(   headers)r%   Zauthenticate_requestr   r   r   messageformr   Zmodel_validatedictr   r
   r$   Zload_access_tokenr   Zload_refresh_tokenr   reversedr   r   Zrevoke_tokenr	   )	selfr&   clienteZ	form_dataZrevocation_requestloadersr   loaderr   r   r   handle&   sZ   	

zRevocationHandler.handleN)
r   r   r   r   r   r   r   r   r	   r5   r   r   r   r   r#   !   s   
 r#   N)dataclassesr   	functoolsr   typingr   r   Zpydanticr   r   Zstarlette.requestsr   Zstarlette.responsesr	   Zmcp.server.auth.errorsr
   Zmcp.server.auth.json_responser   Z&mcp.server.auth.middleware.client_authr   r   Zmcp.server.auth.providerr   r   r   r   r   r#   r   r   r   r   <module>   s    