o
    i.                     @   s   d dl mZmZ d dlmZmZmZmZmZ G dd deZ	G dd de
ZG dd de
ZG d	d
 d
eZG dd deZG dd deZG dd deZdS )    )AnyLiteral)
AnyHttpUrlAnyUrl	BaseModelFieldfield_validatorc                   @   s   e Zd ZU dZeed< dZed ed< dZe	dB ed< dZ
edB ed< dZedB ed< edd	d
ededB dedB fddZdS )
OAuthTokenzG
    See https://datatracker.ietf.org/doc/html/rfc6749#section-5.1
    Zaccess_tokenZBearer
token_typeN
expires_inscoperefresh_tokenbefore)modevreturnc                 C   s   t |tr	| S |S N)
isinstancestrtitle)clsr    r   F/home/app/Keep/.python/lib/python3.10/site-packages/mcp/shared/auth.pynormalize_token_type   s   
zOAuthToken.normalize_token_type)__name__
__module____qualname____doc__r   __annotations__r
   r   r   intr   r   r   classmethodr   r   r   r   r   r	      s   
 
"r	   c                   @      e Zd ZdefddZdS )InvalidScopeErrormessagec                 C   
   || _ d S r   r#   selfr#   r   r   r   __init__      
zInvalidScopeError.__init__Nr   r   r   r   r(   r   r   r   r   r"          r"   c                   @   r!   )InvalidRedirectUriErrorr#   c                 C   r$   r   r%   r&   r   r   r   r(   !   r)   z InvalidRedirectUriError.__init__Nr*   r   r   r   r   r,       r+   r,   c                   @   sX  e Zd ZU dZedddZee dB ed< dZ	e
d dB ed< d	d
gZee
d eB  ed< dgZee ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dZee dB ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dedB dee dB fddZdedB defdd ZdS )!OAuthClientMetadataz
    RFC 7591 OAuth 2.0 Dynamic Client Registration metadata.
    See https://datatracker.ietf.org/doc/html/rfc7591#section-2
    for the full specification.
    .   
min_lengthNredirect_uris)noneZclient_secret_postZclient_secret_basicZprivate_key_jwttoken_endpoint_auth_methodauthorization_coder   )r4   r   z+urn:ietf:params:oauth:grant-type:jwt-bearergrant_typescoderesponse_typesr   client_name
client_urilogo_uricontactstos_uri
policy_urijwks_urijwkssoftware_idsoftware_versionrequested_scoper   c                 C   sT   |d u rd S | d}| jd u rg n| j d}|D ]}||vr'td| q|S )N z%Client was not registered with scope )splitr   r"   )r'   rB   Zrequested_scopesZallowed_scopesr   r   r   r   validate_scopeJ   s   
z"OAuthClientMetadata.validate_scoperedirect_uric                 C   sZ   |d ur| j d u s|| j vrtd| d|S | j d ur)t| j dkr)| j d S td)NzRedirect URI 'z' not registered for clientr.   r   zGredirect_uri must be specified when client has multiple registered URIs)r1   r,   len)r'   rF   r   r   r   validate_redirect_uriT   s   
z)OAuthClientMetadata.validate_redirect_uri)r   r   r   r   r   r1   listr   r   r3   r   r5   r   r7   r   r8   r9   r   r:   r;   r<   r=   r>   r?   r   r@   rA   rE   rH   r   r   r   r   r-   %   s6   
 


r-   c                   @   sR   e Zd ZU dZdZedB ed< dZedB ed< dZe	dB ed< dZ
e	dB ed< dS )OAuthClientInformationFullzn
    RFC 7591 OAuth 2.0 Dynamic Client Registration full response
    (client information plus metadata).
    N	client_idclient_secretclient_id_issued_atclient_secret_expires_at)r   r   r   r   rK   r   r   rL   rM   r   rN   r   r   r   r   rJ   `   s   
 rJ   c                   @   s  e Zd ZU dZeed< eed< eed< dZedB ed< dZee	 dB ed< dgZ
ee	 ed	< dZee	 dB ed
< dZee	 dB ed< dZee	 dB ed< dZee	 dB ed< dZedB ed< dZee	 dB ed< dZedB ed< dZedB ed< dZedB ed< dZee	 dB ed< dZee	 dB ed< dZedB ed< dZee	 dB ed< dZee	 dB ed< dZee	 dB ed< dZedB ed< dS )OAuthMetadataz{
    RFC 8414 OAuth 2.0 Authorization Server Metadata.
    See https://datatracker.ietf.org/doc/html/rfc8414#section-2
    ZissuerZauthorization_endpointZtoken_endpointNregistration_endpointscopes_supportedr6   response_types_supportedresponse_modes_supportedgrant_types_supported%token_endpoint_auth_methods_supported0token_endpoint_auth_signing_alg_values_supportedservice_documentationui_locales_supportedop_policy_uri
op_tos_urirevocation_endpoint*revocation_endpoint_auth_methods_supported5revocation_endpoint_auth_signing_alg_values_supportedintrospection_endpoint-introspection_endpoint_auth_methods_supported8introspection_endpoint_auth_signing_alg_values_supported code_challenge_methods_supported%client_id_metadata_document_supported)r   r   r   r   r   r   rP   rQ   rI   r   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   boolr   r   r   r   rO   l   s0   
 rO   c                   @   s  e Zd ZU dZeed< edddZee ed< dZ	edB ed< dZ
ee dB ed	< ed
gdZee dB ed< dZee dB ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dZedB ed< dZee dB ed< dZee dB ed< dZedB ed< dS )ProtectedResourceMetadatazy
    RFC 9728 OAuth 2.0 Protected Resource Metadata.
    See https://datatracker.ietf.org/doc/html/rfc9728#section-2
    resource.r.   r/   authorization_serversNr>   rQ   header)defaultbearer_methods_supported%resource_signing_alg_values_supportedresource_nameresource_documentationresource_policy_uriresource_tos_uri*tls_client_certificate_bound_access_tokens%authorization_details_types_supported!dpop_signing_alg_values_supported!dpop_bound_access_tokens_required)r   r   r   r   r   r   r   rf   rI   r>   rQ   r   ri   rj   rk   rl   rm   rn   ro   rc   rp   rq   rr   r   r   r   r   rd      s    
 rd   N)typingr   r   Zpydanticr   r   r   r   r   r	   	Exceptionr"   r,   r-   rJ   rO   rd   r   r   r   r   <module>   s    ;