o
    i(                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	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mZ d dlmZ d dlmZmZ G dd de
e ZG dd de	ZeG dd dZdS )    N)	dataclass)Any)uuid4)	BaseModel	RootModelValidationError)Request)Response)stringify_pydantic_error)PydanticJSONResponse) OAuthAuthorizationServerProviderRegistrationErrorRegistrationErrorCode)ClientRegistrationOptions)OAuthClientInformationFullOAuthClientMetadatac                   @   s   e Zd ZU eed< dS )RegistrationRequestrootN)__name__
__module____qualname__r   __annotations__ r   r   X/home/app/Keep/.python/lib/python3.10/site-packages/mcp/server/auth/handlers/register.pyr      s   
 r   c                   @   s"   e Zd ZU eed< edB ed< dS )RegistrationErrorResponseerrorNerror_description)r   r   r   r   r   strr   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 )RegistrationHandlerprovideroptionsrequestreturnc              
      s|  z|  I d H }t|}W n ty- } zttdt|dddW  Y d }~S d }~ww tt }|j	d u r;d|_	d }|j	dkrGt
d}|jd u r[| jjd ur[d| jj|_n/|jd ur| jjd urt|j }t| jj}||sttdd	d
||  dddS ddht|jsttdddddS d|jvrttdddddS tt }	| jjd ur|	| jj nd }
td$i d|d|	d|d|
d|jd|j	d|jd|jd|jd|jd|jd|jd|jd|jd|j d|j!d |j"d!|j#d"|j$}z| j%&|I d H  t|d#dW S  t'y= } ztt|j(|j)dddW  Y d }~S d }~ww )%NZinvalid_client_metadata)r   r   i  )contentstatus_codeZclient_secret_postnone     z Requested scopes are not valid: z, Zauthorization_codeZrefresh_tokenz8grant_types must be authorization_code and refresh_tokencodez?response_types must include 'code' for authorization_code grant	client_idclient_id_issued_atclient_secretclient_secret_expires_atredirect_uristoken_endpoint_auth_methodgrant_typesresponse_typesclient_name
client_urilogo_uriscopecontactstos_uri
policy_urijwks_urijwkssoftware_idsoftware_version   r   )*jsonr   Zmodel_validater   r   r   r
   r   r   r.   secretsZ	token_hexr4   r    Zdefault_scopesjoinvalid_scopessetsplitissubsetr/   r0   inttimeZclient_secret_expiry_secondsr   r-   r1   r2   r3   r5   r6   r7   r8   r9   r:   r;   r   Zregister_clientr   r   r   )selfr!   bodyZclient_metadataZvalidation_errorr)   r+   Zrequested_scopesr@   r*   r,   Zclient_infoer   r   r   handle"   s   
	





	
zRegistrationHandler.handleN)
r   r   r   r   r   r   r   r   r	   rI   r   r   r   r   r      s   
 r   ) r>   rE   dataclassesr   typingr   uuidr   Zpydanticr   r   r   Zstarlette.requestsr   Zstarlette.responsesr	   Zmcp.server.auth.errorsr
   Zmcp.server.auth.json_responser   Zmcp.server.auth.providerr   r   r   Zmcp.server.auth.settingsr   Zmcp.shared.authr   r   r   r   r   r   r   r   r   <module>   s"    