o
    
j                     @   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
    access_token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   B/home/kuhnn/.local/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   r0       r/   r0   c                   @   s  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< edddddddededefddZ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)noneclient_secret_postclient_secret_basicprivate_key_jwttoken_endpoint_auth_methodauthorization_coder   )r;   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_versionr   r   r   r   c                 C   s   |dkrd S |S )N r   r   r   r   r   "_empty_string_optional_url_to_noneJ   s   z6OAuthClientMetadata._empty_string_optional_url_to_nonerequested_scopec                 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+   rK   requested_scopesallowed_scopesr   r   r   r   validate_scope\   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 clientr2   r   zGredirect_uri must be specified when client has multiple registered URIs)r5   r0   len)r+   rQ   r   r   r   validate_redirect_urif   s   
z)OAuthClientMetadata.validate_redirect_uri)!r   r   r    r!   r   r5   listr   r"   r:   r   r<   r   r>   r   r?   r@   r   rA   rB   rC   rD   rE   rF   r   rG   rH   r   r$   objectrJ   rP   rS   r   r   r   r   r1   %   sJ   
 

	
r1   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!   rW   r   r"   rX   rY   r#   rZ   r   r   r   r   rV   r   s   
 rV   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
    issuerauthorization_endpointtoken_endpointNregistration_endpointscopes_supportedr=   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"   r_   r`   rT   r   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   boolr   r   r   r   r[   ~   s0   
 r[   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.r2   r3   authorization_serversNrE   r`   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   ru   rT   rE   r`   r   rx   ry   rz   r{   r|   r}   r~   rr   r   r   r   r   r   r   r   rs      s    
 rs   N)typingr   r   pydanticr   r   r   r   r   r	   	Exceptionr&   r0   r1   rV   r[   rs   r   r   r   r   <module>   s    M