+
    3j$                        ^ RI 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 ^ RIHt ^ RIH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 ] P4                  ! ]4      t ! R R]4      t]]]]]3,          3,          t ! R R]4      t  ! R R]4      t!RR R llt"R R lt#R# )    N)
HTTPStatus)BaseHTTPRequestHandler)
HTTPServer)socketAny)Dict)List)OptionalSet)Tuple)Union)parse_qs)urlparse)	BaseModel)AnacondaAuthConfig)AnacondaAuthSite)AuthenticationErrorc                   <   a  ] tR t^t o RtRtRt. tV 3R ltRt	V t
R# )Resultz;This class is needed to capture the auth code redirect data c                N   < V ^8  d   Qh/ S[ ;R&   S[ ;R&   S[S[ ,          ;R&   # )   	auth_codestatescopes)strr
   )format__classdict__s   "6lib/python3.14/site-packages/anaconda_auth/handlers.py__annotate__Result.__annotate__   s/        O	 
 I      N)__name__
__module____qualname____firstlineno____doc__r   r   r   __annotate_func____static_attributes____classdictcell__)r    s   @r!   r   r      s     EIEF  r$   r   c                      a a ] tR t^%t oRt]! 4       tRV3R lV 3R llltV3R lV 3R lltV3R lV 3R llt	V3R lR	 lt
V3R
 ltRtVtV ;t# )AuthCodeRedirectServerzGA simple http server to handle the incoming auth code redirect from Oryc                R   < V ^8  d   QhRS[ RS[S[ S[3,          RS[S[,          /# )r   	oidc_pathserver_addressconfig)r   r   intr   r   )r   r    s   "r!   r"   #AuthCodeRedirectServer.__annotate__*   s7     
5 
5
5 c3h
5 )*	
5r$   c                   < \         SV `  V\        4       R V n        \	        V P
                  ^ ,          4      V n        Wn        T;'       g    \        4       V n	        R # N)
super__init__AuthCodeRedirectRequestHandlerresultr   r2   	host_namer1   r   r3   )selfr1   r2   r3   	__class__s   &&&&r!   r9   AuthCodeRedirectServer.__init__*   sK     	)GH+/T0034"44 2 4r$   c                   < V ^8  d   QhRR/# )r   returnr/   r%   )r   r    s   "r!   r"   r5   6   s     # #3 #r$   c                V   < V P                   P                  V 4       \        SV `  4       # r7   )_open_serversaddr8   	__enter__)r=   r>   s   &r!   rE    AuthCodeRedirectServer.__enter__6   s%    t$w ""r$   c                0   < V ^8  d   QhRS[ RS[ RS[ RR/# )r   exc_typeexc_valexc_tbrA   Nr   )r   r    s   "r!   r"   r5   :   s)     ; ; ;s ;C ;D ;r$   c                ~   <  V P                   P                  V 4       \        SV `  WV4      #   \         d     Li ; ir7   )rC   removeKeyErrorr8   __exit__)r=   rH   rI   rJ   r>   s   &&&&r!   rN   AuthCodeRedirectServer.__exit__:   sD    	%%d+ w6::  		s   . <<c                *   < V ^8  d   QhRS[ RS[RR/# )r   requestclient_addressrA   N)TRequestr   )r   r    s   "r!   r"   r5   B   s"     

 

h 

 

 

r$   c           
         \        VVV V P                  V P                  V P                  P                  V P                  P
                  R7       R# )z8Finish one request by instantiating RequestHandlerClass.)serverr1   r<   login_success_urllogin_error_urlN)r:   r1   r<   r3   rV   rW   )r=   rQ   rR   s   &&&r!   finish_request%AuthCodeRedirectServer.finish_requestB   s;    &nnnn"kk;; KK77	
r$   c                4   < V ^8  d   Qh/ S[ R,          ;R&   # )r   r/   rC   r   )r   r    s   "r!   r"   r5   %   s      /08 r$   )r3   r<   r1   r;   r7   )r&   r'   r(   r)   r*   setrC   r9   rE   rN   rX   r+   r,   r-   __classcell__r>   r    s   @@r!   r/   r/   %   s>     Q365M
5 
5# #; ;

 

;  r$   r/   c                      a a ] tR t^Ot oRtV3R lV 3R lltV3R lR ltV3R lR ltV3R lR	 ltV3R
 lR lt	V3R lt
RtVtV ;t# )r:   z?Request handler to get the auth code from the redirect from Oryc                >   < V ^8  d   QhRS[ RS[RS[RS[RS[RS[ /# )r   argsr1   r<   rV   rW   kwargs)r   r   )r   r    s   "r!   r"   +AuthCodeRedirectRequestHandler.__annotate__T   sG     * ** * 	*
 * * *r$   c               X   < Wn         W n        W0n        W@n        \        SV `  ! V/ VB  R # r7   )r1   r<   rV   rW   r8   r9   )r=   r1   r<   rV   rW   r`   ra   r>   s   &$$$$*,r!   r9   'AuthCodeRedirectRequestHandler.__init__T   s-     #"!2.$)&)r$   c                *   < V ^8  d   QhRS[ RS[RR/# )r   r   r`   rA   N)r   r   )r   r    s   "r!   r"   rb   e   s"     < <# <c <d <r$   c                    R# )z-Override base method to suppress log message.Nr%   )r=   r   r`   s   &&*r!   log_message*AuthCodeRedirectRequestHandler.log_messagee   s    r$   c                J   < V ^8  d   QhRS[ S[S[S[,          3,          RR/# )r   query_paramsrA   N)r	   r   r
   )r   r    s   "r!   r"   rb   h   s(      c49n)= $ r$   c                h   R V9   d^   RV9   dW   V P                   p\        VR ,          ^ ,          VR,          ^ ,          VP                  R. 4      R7      V P                  n        MV P
                  pV P                  \        P                  4       V P                  RV4       V P                  4        R# )coder   scope)r   r   r   LocationN)rV   r   getrU   r;   rW   send_responser   TEMPORARY_REDIRECTsend_headerend_headers)r=   rj   locations   && r!   _handle_auth+AuthCodeRedirectRequestHandler._handle_authh   s    \!g&=--H!'&v.q1"7+A.#''4"DKK ++H:889X.r$   c                   < V ^8  d   QhRR/# r   rA   Nr%   )r   r    s   "r!   r"   rb   w   s      D r$   c                    V P                  \        P                  4       V P                  R R4       V P	                  4        R# )zContent-typez	text/htmlN)rp   r   	NOT_FOUNDrr   rs   )r=   s   &r!   
_not_found)AuthCodeRedirectRequestHandler._not_foundw   s2    ://05r$   c                   < V ^8  d   QhRR/# rx   r%   )r   r    s   "r!   r"   rb   |   s     , , ,r$   c                    \        R V P                   V P                   24      p\        VP                  4      pVP                  V P
                  8w  d   V P                  4        R# V P                  V4       R# )http://N)r   r<   pathr   queryr1   r{   ru   )r=   
parsed_urlrj   s   &  r!   do_GET%AuthCodeRedirectRequestHandler.do_GET|   sZ    '7		{CD

 0 01 ??dnn,OOl+r$   c                &   < V ^8  d   Qh/ S[ ;R&   # )r   rU   )r/   )r   r    s   "r!   r"   rb   O   s      #" r$   )r<   rW   rV   r1   )r&   r'   r(   r)   r*   r9   rg   ru   r{   r   r+   r,   r-   r\   r]   s   @@r!   r:   r:   O   sB     I* *"< <  
, ,[  r$   r:   c                ^    V ^8  d   QhR\         R\         R\        \        ,          R\         /# )r   redirect_urir   r3   rA   )r   r   r   )r   s   "r!   r"   r"      s2      !+34D+Er$   c                 *   T;'       g    \        4       p\        V 4      pVP                  P                  R 4      w  rE\	        T;'       g    R4      pVP
                  p\        P                  RV  24       \        WtV3VR7      ;_uu_ 4       pVP                  4        RRR4       XP                  p	V	f   \        R4      hV	P                  f   \        R4      hV	P                  V8w  d   \        R4      hV	P                  #   + '       g   i     Ll; i):80zListening on: )r3   Nz!Could not complete authenticationzNo authorization codezState does not match)r   r   netlocsplitr4   r   loggerdebugr/   handle_requestr;   r   r   r   )
r   r   r3   r   r<   portserver_portr1   
web_serverr;   s
   &&&       r!   capture_auth_coder      s     ++)+F,'J ''--c2OIdlld#KI
LL>,01	{+F
 
	!!#

 F~!"EFF!"9::||u!"899!
 
s   DD	c                    V ^8  d   QhRR/# rx   r%   )r   s   "r!   r"   r"      s     
O 
Od 
Or$   c                     \        \        P                  4       F4  p \        P                  ! RV P
                   RV P                   R24       K6  	  R# )zCancel all open AuthCodeRedirectServer instances, which may be blocking their thread waiting
for an auth code.

This function should be called from a separate thread than the servers.

r   r   z/cancelN)listr/   rC   requestsro   r<   r   )rU   s    r!   shutdown_all_serversr      sE     -;;< 	wv//0&2D2D1EWMN =r$   r7   )$logginghttpr   http.serverr   r   r   typingr   r	   r
   r   r   r   r   urllib.parser   r   r   pydanticr   anaconda_auth.configr   r   anaconda_auth.exceptionsr   	getLoggerr&   r   r   bytesrS   r/   r:   r   r   r%   r$   r!   <module>r      s      . "         ! !   3 1 8			8	$Y  uf}--.'
Z '
T5,%; 5,p>
Or$   