+
    Q(i                    X   R t ^ RIHt ^ RIHt ^ RI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HtHtHtHtHtHtHt ]! ]4      tR$R R llt] ! R R4      4       t] ! R R4      4       t R%R R llt!]R8X  d    ^ RI"t"^ RIt]! 4       t#]$! R4       ]$! R4       ]$! R]# R24       ]$! R]# R24       ]$! R]# R24       ]$! R4       ]$! 4        ]!! ]#RR7      t%]"PL                  ! R]# R24       ]PN                  ! ]%PP                  PR                  R ]#R!R"R#7       R# R# )&z
OAuth callback server for handling authorization code flows.

This module provides a reusable callback server that can handle OAuth redirects
and display styled responses to users.
)annotations)	dataclassN)	Starlette)Request)Route)ConfigServer)find_available_port)
get_logger)HELPER_TEXT_STYLESINFO_BOX_STYLESSTATUS_MESSAGE_STYLEScreate_info_boxcreate_logocreate_pagecreate_secure_html_responsecreate_status_messagec          
     ,    V ^8  d   QhRRRRRRRRRR/# )	   messagestr
is_successbooltitle
server_url
str | Nonereturn )formats   "c/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/client/oauth_callback.py__annotate__r    "   s:     * *** * 	*
 	*    c                    V'       d   RMRpRpV'       d   V'       d   \        RV 2RRR7      pMV'       g   \        V RRRR7      pR\        4        R	\        WAR
7       R	V R2p\        \        ,           \
        ,           p\        VVVR7      # )z2Create a styled HTML response for OAuth callbacks.zAuthentication successfulzAuthentication failed zConnected to: T)centered	monospace)is_errorr$   r%   z-
        <div class="container">
            z
            r   z
            <div class="close-instruction">
                You can safely close this tab now.
            </div>
        </div>
    )contentr   additional_styles)r   r   r   r   r   r   r   )r   r   r   r   status_titledetail_infor(   r)   s   &&&&    r   create_callback_htmlr,   "   s     (2#7N 
 Kj%ZL)DD
 %dTT

]O "<GH IM 		G .?BTT+ r!   c                  r    ] tR t^Ot$ RtR]R&   RtR]R&   RtR]R&   RtR]R&   ]	R R l4       t
R	 R
 ltRtR# )CallbackResponseNr   codestateerrorerror_descriptionc                    V ^8  d   QhRRRR/# )r   datadict[str, str]r   r.   r   )r   s   "r   r    CallbackResponse.__annotate__W   s     R R^ R0@ Rr!   c           
     	    T ! R/ VP                  4        UUu/ uF  w  r#W P                  9   g   K  W#bK  	  uppB # u uppi )Nr   )items__annotations__)clsr4   kvs   &&  r   	from_dictCallbackResponse.from_dictV   s9    Qtzz|P|tqq<O<O7Odad|PQQPs   ==c                   V ^8  d   QhRR/# )r   r   r5   r   )r   s   "r   r    r6   Z   s     I I Ir!   c                	v    V P                   P                  4        UUu/ uF  w  rVf   K  WbK  	  upp# u uppi )N)__dict__r8   )selfr;   r<   s   &  r   to_dictCallbackResponse.to_dictZ   s1    !%!4!4!6H!6!!6HHHs   55r   )__name__
__module____qualname____firstlineno__r/   r9   r0   r1   r2   classmethodr=   rC   __static_attributes__r   r!   r   r.   r.   O   sK    D*E:E:$(z(R RI Ir!   r.   c                  F    ] tR t^^t$ RtRtR]R&   RtR]R&   RtR]R&   Rt	R# )	OAuthCallbackResultzSContainer for OAuth callback results, used with anyio.Event for async coordination.Nr   r/   r0   zException | Noner1   r   )
rE   rF   rG   rH   __doc__r/   r9   r0   r1   rJ   r   r!   r   rL   rL   ^   s$    ]D*E:"E"r!   rL   	/callbackc               0    V ^8  d   QhRRRRRRRRR	R
RR/# )r   portintcallback_pathr   r   r   result_containerzOAuthCallbackResult | Noneresult_readyzanyio.Event | Noner   r   r   )r   s   "r   r    r    g   sL     h h
hh h 1	h
 %h hr!   c                ~   aaa R VVV3R llp\        \        W4      .R7      p\        \        VRV RRRR7      4      # )	a  
Create an OAuth callback server.

Args:
    port: The port to run the server on
    callback_path: The path to listen for OAuth redirects on
    server_url: Optional server URL to display in success messages
    result_container: Optional container to store callback results
    result_ready: Optional event to signal when callback is received

Returns:
    Configured uvicorn Server instance (not yet running)
c                   V ^8  d   QhRR/# )r   requestr   r   )r   s   "r   r    2create_oauth_callback_server.<locals>.__annotate__|   s     F
 F
 F
r!   c                L  <"   \        V P                  4      p\        P                  V4      pVP                  '       dp   VP
                  ;'       g    RpVP                  R8X  d   RpMRV 2pSe%   Se!   \        V4      Sn        SP                  4        \        \        VRR7      RR7      # VP                  '       gC   R	pSe%   Se!   \        V4      Sn        SP                  4        \        \        VRR7      RR7      # VP                  fC   R
pSe%   Se!   \        V4      Sn        SP                  4        \        \        VRR7      RR7      # Se7   Se3   VP                  Sn
        VP                  Sn        SP                  4        \        \        RRSR7      4      # 5i)z:Handle OAuth callback requests with proper HTML responses.zUnknown erroraccess_deniedz.Access was denied by the authorization server.zAuthorization failed: Fr'   i  )status_codez3No authorization code was received from the server.z=The OAuth server did not return the expected state parameter.r#   T)r   r   )dictquery_paramsr.   r=   r1   r2   RuntimeErrorsetr   r,   r/   r0   )rW   r]   callback_response
error_descuser_messagerS   rT   r   s   &    r   callback_handler6create_oauth_callback_server.<locals>.callback_handler|   s    G001,66|D"""*<<OOJ !&&/9O!7
|D  +0H)5l)C &  ".$ $    !%%%PL  +0H)5l)C &  ".$ $    ""*O 
  +0H)5l)C &  ".$ $    'L,D$5$:$:!%6%<%<"* L
 	
s   AF$A-F$C#F$)routes	127.0.0.1offwarningzwebsockets-sansio)apphostrP   lifespan	log_levelws)r   r   r   r   )rP   rR   r   rS   rT   rc   ri   s   &&fff  r   create_oauth_callback_serverrn   g   sK    *F
 F
P E-BC
DC"	
	 	r!   __main__u   🎭 OAuth Callback Test Serveru   📍 Test URLs:z  Success: http://localhost:z /callback?code=test123&state=xyzz  Error:   http://localhost:z=/callback?error=access_denied&error_description=User%20deniedz  Missing: http://localhost:u   🛑 Press Ctrl+C to stopz'https://fastmcp-test-server.example.com)rP   r   zhttp://localhost:rf   rh   F)rj   rP   rl   
access_log)TzFastMCP OAuthN)rN   NNN)*rM   
__future__r   dataclassesr   anyiostarlette.applicationsr   starlette.requestsr   starlette.routingr   uvicornr   r   fastmcp.utilities.httpr	   fastmcp.utilities.loggingr
   fastmcp.utilities.uir   r   r   r   r   r   r   r   rE   loggerr,   r.   rL   rn   
webbrowserrP   printserveropenrunconfigri   r   r!   r   <module>r      sR   # !  , & # " 6 0	 	 	 
H	*Z I I I # # #hV z3 D	
+,	
	(.N
OP	
&tf,ij 
(i
89	
%&	G *GF
 OO'v-MNO KK5 r!   