o
    h/                     @   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   b/var/www/html/openai_agents/venv/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              
      sl  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 }d }|j	dkr?t
d}|jd u rS| jjd urSd| 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'y5 } ztt|j(|j)dddW  Y d }~S d }~ww )$Ninvalid_client_metadata)r   r   i  )contentstatus_codenone     z Requested scopes are not valid: z, authorization_code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   model_validater   r   r   r
   r   r   r1   secrets	token_hexr7   r    default_scopesjoinvalid_scopessetsplitissubsetr2   r3   inttimeclient_secret_expiry_secondsr   r0   r4   r5   r6   r8   r9   r:   r;   r<   r=   r>   r   register_clientr   r   r   )selfr!   bodyclient_metadatavalidation_errorr,   r.   requested_scopesrF   r-   r/   client_infoer   r   r   handle"   s   
	




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