§
    ezniô  ã                   ób   — d dl Z d dlmZmZmZmZ d dlmZmZm	Z	m
Z
 e› d�Z G d„ d¦  «        ZdS )é    N)ÚHUB_API_ROOTÚHUB_WEB_ROOTÚPREFIXÚrequest_with_credentials)ÚLOGGERÚSETTINGSÚemojisÚis_colabz/settings?tab=api+keysc                   óL   — e Zd ZdZdxZxZZdd„Zdd„Zde	fd„Z
de	fd	„Zd
„ ZdS )ÚAutha]  
    Manages authentication processes including API key handling, cookie-based authentication, and header generation.

    The class supports different methods of authentication:
    1. Directly using an API key.
    2. Authenticating using browser cookies (specifically in Google Colab).
    3. Prompting the user to enter an API key.

    Attributes:
        id_token (str or bool): Token used for identity verification, initialized as False.
        api_key (str or bool): API key for authentication, initialized as False.
        model_key (bool): Placeholder for model key, initialized as False.
    FÚ c                 ó`  — |                      d¦  «        d         }|pt          j        dd¦  «        | _        | j        rR| j        t          j        d¦  «        k    r |rt	          j        t          › d�¦  «         dS |                      ¦   «         }n7t          ¦   «         r|  	                    ¦   «         }n|  
                    ¦   «         }|r=t          j        d| j        i¦  «         |rt	          j        t          › d�¦  «         dS dS |r%t	          j        t          › dt          › �¦  «         dS dS )	z¾
        Initialize the Auth class with an optional API key.

        Args:
            api_key (str, optional): May be an API key or a combination API key and model ID, i.e. key_id
        Ú_r   Úapi_keyr   u   Authenticated âœ…Nu!   New authentication successful âœ…zRetrieve API key from )Úsplitr   Úgetr   r   Úinfor   Úauthenticater
   Úauth_with_cookiesÚrequest_api_keyÚupdateÚAPI_KEY_URL)Úselfr   ÚverboseÚsuccesss       út/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/ultralytics/hub/auth.pyÚ__init__zAuth.__init__   sS  € ð —-’- Ñ$Ô$ QÔ'ˆð Ð=¥(¤,¨y¸"Ñ"=Ô"=ˆŒð Œ<ð 	-àŒ|�xœ|¨IÑ6Ô6Ò6Ð6àð >Ý”K¥6Ð <Ð <Ð <Ñ=Ô=Ð=Ø�ð ×+Ò+Ñ-Ô-��å‰ZŒZð 	-à×,Ò,Ñ.Ô.ˆGˆGð ×*Ò*Ñ,Ô,ˆGð ð 	HÝŒO˜Y¨¬Ð5Ñ6Ô6Ð6àð JÝ”�vÐHÐHÐHÑIÔIÐIÐIÐIðJð Jàð 	HÝŒK�6ÐFÐF½ÐFÐFÑGÔGÐGÐGÐGð	Hð 	Hó    é   c                 óh  — ddl }t          |¦  «        D ]{}t          j        t          › d|dz   › d|› �¦  «         |                      dt
          › d�¦  «        }|                     d¦  «        d         | _        |                      ¦   «         r d	S Œ|t          t          t          › d
�¦  «        ¦  «        ‚)zX
        Prompt the user to input their API key.

        Returns the model ID.
        r   NzLogin. Attempt é   z of zEnter API key from ú r   Tu   Failed to authenticate â�Œ)ÚgetpassÚranger   r   r   r   r   r   r   ÚConnectionErrorr	   )r   Úmax_attemptsr#   ÚattemptsÚ	input_keys        r   r   zAuth.request_api_keyD   sÂ   € ð 	ˆˆˆÝ˜lÑ+Ô+ð 	ð 	ˆHÝŒK�6ÐRÐR°(¸Q±,ÐRÐRÀLÐRÐRÑSÔSÐSØŸšÐ(L½kÐ(LÐ(LÐ(LÑMÔMˆIØ$Ÿ?š?¨3Ñ/Ô/°Ô2ˆDŒLØ× Ò Ñ"Ô"ð Ø�t�tðå�f­Ð%JÐ%JÐ%JÑKÔKÑLÔLÐLr   Úreturnc                 ór  — 	 |                       ¦   «         x}rWt          j        t          › d�|¬¦  «        }|                     ¦   «                              dd¦  «        st          d¦  «        ‚dS t          d¦  «        ‚# t          $ r. dx| _        | _        t          j
        t          › d�¦  «         Y dS w xY w)	z¶
        Attempt to authenticate with the server using either id_token or API key.

        Returns:
            bool: True if authentication is successful, False otherwise.
        z/v1/auth)Úheadersr   FzUnable to authenticate.Tz#User has not authenticated locally.u   Invalid API key âš ï¸�)Úget_auth_headerÚrequestsÚpostr   Újsonr   r%   Úid_tokenr   r   Úwarningr   )r   ÚheaderÚrs      r   r   zAuth.authenticateS   sÈ   € ð
	Ø×-Ò-Ñ/Ô/Ð/ˆvð Ý”M¥\Ð";Ð";Ð";ÀVÐLÑLÔL�Ø—v’v‘x”x—|’| I¨uÑ5Ô5ð EÝ)Ð*CÑDÔDÐDØ�tÝ!Ð"GÑHÔHÐHøÝð 	ð 	ð 	Ø+0Ð0ˆDŒM˜DœLÝŒN�fÐ<Ð<Ð<Ñ=Ô=Ð=Ø�5�5ð	øøøs   ‚A+A> Á/A> Á>4B6Â5B6c                 óV  — t          ¦   «         sdS 	 t          t          › d�¦  «        }|                     dd¦  «        rE|                     di ¦  «                             dd¦  «        | _        |                      ¦   «          dS t          d¦  «        ‚# t          $ r d| _        Y dS w xY w)	zô
        Attempt to fetch authentication via cookies and set id_token. User must be logged in to HUB and running in a
        supported browser.

        Returns:
            bool: True if authentication is successful, False otherwise.
        Fz/v1/auth/autor   ÚdataÚidTokenNTz/Unable to fetch browser authentication details.)r
   r   r   r   r0   r   r%   )r   Úauthns     r   r   zAuth.auth_with_cookiesf   sº   € õ ‰zŒzð 	Ø�5ð		Ý,µÐ-KÐ-KÐ-KÑLÔLˆEØ�yŠy˜ EÑ*Ô*ð Ø %§	¢	¨&°"Ñ 5Ô 5× 9Ò 9¸)ÀTÑ JÔ J�”Ø×!Ò!Ñ#Ô#Ð#Ø�tÝ!Ð"SÑTÔTÐTøÝð 	ð 	ð 	Ø!ˆDŒMØ�5�5ð	øøøs   ’A0B ÂB ÂB(Â'B(c                 óL   — | j         rdd| j         › �iS | j        r	d| j        iS dS )z·
        Get the authentication header for making API requests.

        Returns:
            (dict): The authentication header if id_token or API key is set, None otherwise.
        ÚauthorizationzBearer z	x-api-keyN)r0   r   )r   s    r   r,   zAuth.get_auth_header{   sE   € ð Œ=ð 	/Ø#Ð%>¨t¬}Ð%>Ð%>Ð?Ð?ØŒ\ð 	/Ø ¤Ð.Ð.ð	/ð 	/r   N)r   F)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r   Ú	model_keyr   r   Úboolr   r   r,   © r   r   r   r      s¥   € € € € € ðð ð &+Ð*€HÐ*ˆw˜ð'Hð 'Hð 'Hð 'HðRMð Mð Mð Mð˜dð ð ð ð ð& 4ð ð ð ð ð*
/ð 
/ð 
/ð 
/ð 
/r   r   )r-   Úultralytics.hub.utilsr   r   r   r   Úultralytics.utilsr   r   r	   r
   r   r   r@   r   r   ú<module>rC      s¢   ðð €€€à ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ð ^Ø @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @Ð @àÐ5Ð5Ð5€ðz/ð z/ð z/ð z/ð z/ñ z/ô z/ð z/ð z/ð z/r   