+
    wi#                     V   ^ RI HtHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI H!t! ^ RI"H#t#H$t$ ^ RI%H&t& ^ RI'H(t( R R lt)Rt*Rt+Rt,Rt-R R lt.R%R R llt/R R  lt0R! R" lt1R%R# R$ llt2R# )&    )	AwaitableCallable)Any)urlparse
AnyHttpUrl)CORSMiddleware)Request)Response)Routerequest_response)ASGIApp)AuthorizationHandler)MetadataHandler)RegistrationHandler)RevocationHandler)TokenHandler)ClientAuthenticator) OAuthAuthorizationServerProvider)ClientRegistrationOptionsRevocationOptions)MCP_PROTOCOL_VERSION_HEADER)OAuthMetadatac                $    V ^8  d   QhR\         /# )   urlr   )formats   "J/home/ubuntu/.local/lib/python3.14/site-packages/mcp/server/auth/routes.py__annotate__r      s     D DZ D    c                2   V P                   R8w  dL   V P                  R8w  d;   V P                  e-   V P                  P                  R4      '       g   \        R4      hV P                  '       d   \        R4      hV P
                  '       d   \        R4      hR# )z
Validate that the issuer URL meets OAuth 2.0 requirements.

Args:
    url: The issuer URL to validate

Raises:
    ValueError: If the issuer URL is invalid
https	localhostNz	127.0.0.1zIssuer URL must be HTTPSz#Issuer URL must not have a fragmentz'Issuer URL must not have a query string)schemehost
startswith
ValueErrorfragmentquery)r   s   &r   validate_issuer_urlr*      sw     	

gHH#XX!#((*=*=k*J*J344 |||>??
yyyBCC r    z
/authorizez/tokenz	/registerz/revokec                    V ^8  d   QhR\         \        .\        \        \        ,          ,          3,          R\        \
        ,          R\        /# )r   handlerallow_methodsreturn)r   r
   r   r   liststrr   )r   s   "r   r   r   8   s@     
 
wiIh,?!??@
9
 
r    c                 @    \        \        V 4      R V\        .R7      pV# )*)appallow_originsr-   allow_headers)r	   r   r   )r,   r-   cors_apps   && r   cors_middlewarer7   8   s)     W%#23	H Or    Nc                    V ^8  d   QhR\         \        \        \        3,          R\        R\        R,          R\        R,          R\        R,          R\
        \        ,          /# )r   provider
issuer_urlservice_documentation_urlNclient_registration_optionsrevocation_optionsr.   )r   r   r   r   r   r/   r   )r   s   "r   r   r   E   sj     N N.sC}=NN  *D0N ";T!A	N
 *D0N 
%[Nr    c                 
   \        V4       T;'       g    \        4       pT;'       g    \        4       p\        VVVV4      p\	        V 4      p\        R \        \        V4      P                  RR.4      RR.R7      \        \        \        V 4      P                  RR.R7      \        \        \        \        W4      P                  RR.4      RR.R7      .pVP                  '       dG   \        V VR7      pVP                  \        \         \        VP                  RR.4      RR.R7      4       VP                  '       dE   \#        W4      p	VP                  \        \$        \        V	P                  RR.4      RR.R7      4       V# )z'/.well-known/oauth-authorization-serverGETOPTIONSendpointmethodsPOST)options)r*   r   r   build_metadatar   r   r7   r   handleAUTHORIZATION_PATHr   
TOKEN_PATHr   enabledr   appendREGISTRATION_PATHr   REVOCATION_PATH)
r9   r:   r;   r<   r=   metadataclient_authenticatorroutesregistration_handlerrevocation_handlers
   &&&&&     r   create_auth_routesrS   E   s    
#"="\"\AZA\+BB/@/B!#	H /x8 	5$)00	" I&	
 	 *(3::FO	
 	$X<CC# Y'	
!F4 #***2/ 
 	!((//Y'  +		
 !!!.xN(&--Y'  +		
 Mr    c          
      b    V ^8  d   QhR\         R\         R,          R\        R\        R\        /# )r   r:   r;   Nr<   r=   r.   )r   r   r   r   )r   s   "r   r   r      s?     % %%)D0% ";% *	%
 %r    c                 8   \        \        V 4      P                  R 4      \        ,           4      p\        \        V 4      P                  R 4      \        ,           4      p\        V VVVP                  R.RRR.RR.RVRRRRR.R7      pVP                  '       d4   \        \        V 4      P                  R 4      \        ,           4      Vn	        VP                  '       d=   \        \        V 4      P                  R 4      \        ,           4      Vn        RR.Vn        V# )	/codeNauthorization_coderefresh_tokenclient_secret_postclient_secret_basicS256)issuerauthorization_endpointtoken_endpointscopes_supported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introspection_endpoint code_challenge_methods_supported)r   r0   rstriprH   rI   r   valid_scopesrJ   rL   registration_endpointrM   revocation_endpoint*revocation_endpoint_auth_methods_supported)r:   r;   r<   r=   authorization_url	token_urlrN   s   &&&&   r   rF   rF      s    #3z?#9#9##>AS#ST3z?11#6CDI 0 4AA"(!%3_E/CEZ.[9=7!#*0H& #***)3C
O4J4J34ORc4c)d& !!!'1#j/2H2H2MP_2_'`$?SUj>k;Or    c                0    V ^8  d   QhR\         R\         /# )r   resource_server_urlr.   r   )r   s   "r   r   r      s     p pZ pJ pr    c                    \        \        V 4      4      pVP                  R8w  d   VP                  MRp\        VP                   RVP
                   RV 24      # )ue  
Build RFC 9728 compliant protected resource metadata URL.

Inserts /.well-known/oauth-protected-resource between host and resource path
as specified in RFC 9728 §3.1.

Args:
    resource_server_url: The resource server URL (e.g., https://example.com/mcp)

Returns:
    The metadata URL (e.g., https://example.com/.well-known/oauth-protected-resource/mcp)
rV    z://z%/.well-known/oauth-protected-resource)r   r0   pathr   r$   netloc)rt   parsedresource_paths   &  r   build_resource_metadata_urlr{      sQ     c-./F#);;##5FKK2Ms6==/9^_l^mnoor    c                    V ^8  d   QhR\         R\        \         ,          R\        \        ,          R,          R\        R,          R\         R,          R\        \        ,          /# )r   resource_urlauthorization_serversr`   Nresource_nameresource_documentationr.   )r   r/   r0   r   )r   s   "r   r   r      s_     , ,,
+, 3i$&, :	,
 '-, 
%[,r    c                    ^ RI Hp ^ RIHp V! V VVVVR7      pV! V4      p\	        V 4      p	\        \        V	4      4      p
V
P                  p\        V\        VP                  RR.4      RR.R7      .# )a]  
Create routes for OAuth 2.0 Protected Resource Metadata (RFC 9728).

Args:
    resource_url: The URL of this resource server
    authorization_servers: List of authorization servers that can issue tokens
    scopes_supported: Optional list of scopes supported by this resource

Returns:
    List of Starlette routes for protected resource metadata
) ProtectedResourceMetadataHandler)ProtectedResourceMetadata)resourcer~   r`   r   r   r?   r@   rA   )!mcp.server.auth.handlers.metadatar   mcp.shared.authr   r{   r   r0   rw   r   r7   rG   )r}   r~   r`   r   r   r   r   rN   r,   metadata_urlry   well_known_paths   &&&&&       r    create_protected_resource_routesr      s    $ S9(3)#5H /x8G /|<Lc,'(FkkO 	$W^^eY5GHI&	
 r    )NNN)3collections.abcr   r   typingr   urllib.parser   pydanticr   starlette.middleware.corsr	   starlette.requestsr
   starlette.responsesr   starlette.routingr   r   starlette.typesr   "mcp.server.auth.handlers.authorizer   r   r   !mcp.server.auth.handlers.registerr   mcp.server.auth.handlers.revoker   mcp.server.auth.handlers.tokenr   &mcp.server.auth.middleware.client_authr   mcp.server.auth.providerr   mcp.server.auth.settingsr   r   mcp.server.streamable_httpr   r   r   r*   rH   rI   rL   rM   r7   rS   rF   r{   r    r    r   <module>r      s~    /  !  4 & ( 5 # C = A = 7 F E Q B )D4 " 
 
Nb%Pp&, ,r    