
    -:j                     X   d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZmZ ddlmZ dd	lmZmZmZmZ dd
lmZmZ ddlmZmZ ddlmZmZ  ej<                  e      Z  ed      Z!e!jE                  dg d      	 	 	 d0dedee# ejH                  d      f   dee# ejH                  d      f   ddfd       Z%e!jE                  dddg      	 d1dee&dz   ejH                  d      f   ddfd       Z'de&dz  fd Z(e!jE                  d!d"d#g      	 	 d2dee&dz   ejH                  d$      f   dee# ejH                  d      f   ddfd%       Z)e!jE                  d&d'g      d3d(       Z*e!jE                  dd)d*g      d3d+       Z+e!jE                  d,d-d.g      d3d/       Z,y)4a  Contains commands to authenticate to the Hugging Face Hub and interact with your repositories.

Usage:
    # login with a browser (OAuth device flow)
    hf auth login

    # login with an explicit token
    hf auth login --token=hf_*** --add-to-git-credential

    # switch between tokens
    hf auth switch

    # list all tokens
    hf auth list

    # logout from all tokens
    hf auth logout

    # check which account you are logged in as
    hf auth whoami
    )	AnnotatedN)ENDPOINT)whoami   )_save_oauth_token	auth_listauth_switchloginlogout)CLIError)get_stored_tokens	get_tokenloggingselect_choice)poll_device_tokenrequest_device_code   )TokenOpttyper_factory)OutputFormatoutz,Manage authentication (login, logout, etc.).)helpr
   )zhf auth loginzhf auth login --token $HF_TOKENz7hf auth login --token $HF_TOKEN --add-to-git-credentialzhf auth login --force)examplestokenadd_to_git_credentialzTSave to git credential helper. Useful only if you plan to run git commands directly.forcez)Force re-login even if already logged in.returnc           	         | !t         j                  t        j                  k(  rt	        | ||        yt         j                  t        j
                  k7  rt        d      |s!t               t        j                  d       yt               }t        j                  d|d    d|d	    d
|d    d       t        |      }t        |      \  }}t        j                  d| d| d       y)zNLogin from your browser, or using a token from huggingface.co/settings/tokens.N)r   r   skip_if_logged_inzr`hf auth login` is interactive and does not support --format json/quiet. Pass --token for a non-interactive login.z;Already logged in. Use `hf auth login --force` to re-login.)agentzAsk the user to open verification_uri_completez! in a browser and enter the code 	user_codez. The code expires in 
expires_inz& seconds. Waiting for authorization...zLogin successful: logged in as z (token saved as 'z').)r   moder   humanr
   r    r   r   textr   r   r   )r   r   r   device_inforesponse
token_nameusernames          Z/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/cli/auth.py
auth_loginr,   9   s    2 CHH(:(::E1F^cZcd xx<%%%8
 	
 Y[,TU%'KHH#K0K$L#MMn;'((>{<?X>Y Z++ !-H,X6JHH4XJ>PQ[P\\_`a    r   zhf auth logoutz$hf auth logout --token-name my-tokenr)   zName of token to logoutc                     t        |        y)zLogout from a specific token.r)   N)r   r/   s    r+   auth_logoutr0   o   s     j!r-   c                      t        t               j                               } | st        j	                  d       y t
        j                  t        j                  k7  rt        d      | t        d|          S )Nz+No stored tokens found. Please login first.z;Use --token-name to select a token in non-interactive mode.zSelect a token to switch to:)listr   keysloggererrorr   r$   r   r%   r   r   )token_namess    r+   _select_token_namer7   }   s]    (*//12KBC
xx<%%%TUU}%C[QRRr-   switchzhf auth switchz$hf auth switch --token-name my-tokenzName of the token to switch toc                 x    | 
t               } | t        d       t        j                         t	        | |       y)zSwitch between access tokens.Nz!No token name provided. Aborting.)r   )r7   printtyperExitr	   )r)   r   s     r+   auth_switch_cmdr=      s8    & ')
12jjl
2GHr-   z	list | lszhf auth listc                      t                y)zList all stored access tokens.N)r    r-   r+   auth_list_cmdr@      s	     Kr-   zhf auth tokenz8hf auth token | xargs curl -H 'Authorization: Bearer {}'c                      t               } | +t        j                  d       t        j                  d      t        |        t        j                  d       y)z)Print the current access token to stdout.Nz)Not logged in. Run `hf auth login` first.r   codez@Run `hf auth whoami` to see which account this token belongs to.)r   r   r5   r;   r<   r:   hint)r   s    r+   
auth_tokenrE      s@     KE}		=>jja  	%LHHOPr-   r   zhf auth whoamizhf auth whoami --format jsonc                      t               } | +t        j                  d       t        j                  d      t        |       }dj                  d |d   D              xs d}t        dk7  rt        nd}t        j                  d	|d
   ||       y)z;Find out which huggingface.co account you are logged in as.NzNot logged inr   rB   ,c              3   &   K   | ]	  }|d      yw)nameNr?   ).0orgs     r+   	<genexpr>zauth_whoami.<locals>.<genexpr>   s     8CCK8s   orgszhttps://huggingface.coz	Logged inrI   )userrM   endpoint)	r   r   r5   r;   r<   r   joinr   result)r   inforM   rO   s       r+   auth_whoamirS      sv     KE}		/"jja  %=D8884<88@DD#'??xTHJJ{fD8Lr-   )NFF)N)NF)r   N)-__doc__typingr   r;   huggingface_hub.constantsr   huggingface_hub.hf_apir   _loginr   r   r	   r
   r   errorsr   utilsr   r   r   r   utils._oauth_devicer   r   
_cli_utilsr   r   _outputr   r   
get_logger__name__r4   auth_clicommandboolOptionr,   strr0   r7   r=   r@   rE   rS   r?   r-   r+   <module>re      s  ,   . ) M M  H H H / & 
		H	% LM 
    	 	*b*b$g	
	*b <	
	*b 
*b*bZ 
 FG   		"d
34	6"
 
"	"	SC$J 	S 
 FG   	 	Id
1	
	I %g	
	I 
I	I. 
+(89 :
 
'_6p$qrQ sQ 
(&68V%WXM YMr-   