
    )@                     ,   S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKrSrSrSrSrSrSrSr\\\\/rSr " S S\R8                  5      r " S S\5      r " S S\5      rS rS r  " S S\RB                  " \RD                  \#5      5      r$ " S S\$5      r% " S  S!\$5      r& " S" S#\$5      r' " S$ S%\$5      r( " S& S'\$5      r) " S( S)\$5      r*S0S* jr+S+ r,S, r-       S1S- jr.S. r/S/ r0g)2z#A library to support auth commands.    N)check_browser)config)
exceptions)log)
properties)yaml)
console_io)creds)fileszH764086051850-6qr4p6gpi6hn506pt8ejuq83di341hur.apps.googleusercontent.comzd-FL95Q19q7MQmFpd7hHD0Tyz.https://www.googleapis.com/auth/cloud-platformz0https://www.googleapis.com/auth/sqlservice.loginz%https://www.googleapis.com/auth/drivez.https://www.googleapis.com/auth/userinfo.emailopenid	installedc                       \ rS rSrSrSrg)Error8   z A base exception for this class. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       'lib/googlecloudsdk/api_lib/auth/util.pyr   r   8   s    (r   r   c                       \ rS rSrSrSrg)InvalidClientSecretsError=   z:An error for when we fail to load the client secrets file.r   Nr   r   r   r   r   r   =   s    Br   r   c                       \ rS rSrSrSrg)BadCredentialFileExceptionB   z,Raised when credentials file cannot be read.r   Nr   r   r   r   r   r   B   s    4r   r   c                 L    [         R                  " U 5      n[        U[        5      (       d  [        SR	                  U 5      5      eU$ ! [         a  n[        SR	                  X5      5      eSnAf[         R
                   a  n[        SR	                  X5      5      eSnAff = f)a  Returns the JSON content of a credentials config file.

This function is useful when the content of a file need to be inspected first
before determining how to handle it (how to initialize the underlying
credentials). Only UTF-8 JSON files are supported.

Args:
  filename (str): The filepath to the ADC file representing credentials.

Returns:
  Optional(Mapping): The JSON content.

Raises:
  BadCredentialFileException: If JSON parsing of the file fails.
z"File {0} is not utf-8 encoded: {1}Nz!Could not read json file {0}: {1}zCould not read json file {0})r   	load_pathUnicodeDecodeErrorr   formatYAMLParseError
isinstancedict)filenamecontentes      r   GetCredentialsConfigFromFiler+   G   s    "nnX&G 
GT	"	"
$&--h79 9	. 
 B
$,33H@B B			 
$%H%O%O&  s#   A	 	
B#A--B#BB#c                     SSK Jn  UR                  U 5      (       a/  [        R                  " UR
                  R                  5       5        g[        R                  " U5        g)z2Prints help messages when auth flow throws errors.r   )context_awareN)googlecloudsdk.corer-   IsContextAwareAccessDeniedErrorr   errorContextAwareAccessErrorGet)excdefault_help_msgr-   s      r   _HandleFlowErrorr5   j   s@     022377IIm33779:IIr   c                   P    \ rS rSrSrSrS	S jr\R                  S 5       r	S r
Srg)

FlowRunneru   zBase auth flow runner class.

Attributes:
   _scopes: [str], The list of scopes to authorize.
   _client_config: The client configuration in the Google client secrets
     format.
z,There was a problem with web authentication.Nc                 R    Xl         X l        X0l        U R                  5       U l        g N)_scopes_client_config_redirect_uri_CreateFlow_flow)selfscopesclient_configredirect_uris       r   __init__FlowRunner.__init__   s#    L'%!!#DJr   c                     g r:   r   )r@   s    r   r>   FlowRunner._CreateFlow   s    r   c                     SSK Jn   U R                  R                  " S0 UD6$ ! UR                   a  n[        X0R                  5        e S nAff = f)Nr   flowr   )googlecloudsdk.core.credentialsrJ   r?   Runr   r5   _FLOW_ERROR_HELP_MSG)r@   kwargsc_flowr*   s       r   rL   FlowRunner.Run   sE    >ZZ^^%f%%<< q334s   $ AA

A)r<   r?   r=   r;   r:   )r   r   r   r   r   rM   rD   abcabstractmethodr>   rL   r   r   r   r   r7   r7   u   s4     H$ 	 	r   r7   c                       \ rS rSrSrS rSrg)OobFlowRunner   zA flow runner to run OobFlow.c                     SSK Jn  UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9$ Nr   rI   autogenerate_code_verifier)rK   rJ   OobFlowfrom_client_configr<   r;   r   VALUESauthdisable_code_verifierGetBoolr@   rO   s     r   r>   OobFlowRunner._CreateFlow   sQ    >>>,,'1'8'8'='=		wwy$) - * *r   r   Nr   r   r   r   r   r>   r   r   r   r   rT   rT      s
    %*r   rT   c                       \ rS rSrSrS rSrg)NoBrowserFlowRunner   z#A flow runner to run NoBrowserFlow.c                     SSK Jn  UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9$ rW   )rK   rJ   NoBrowserFlowr[   r<   r;   r   r\   r]   r^   r_   r`   s     r   r>   NoBrowserFlowRunner._CreateFlow   sS    >22'1'8'8'='=		wwy$) 3 * *r   r   Nrb   r   r   r   rd   rd      s
    +*r   rd   c                       \ rS rSrSrS rSrg)"RemoteLoginWithAuthProxyFlowRunner   z2A flow runner to run RemoteLoginWithAuthProxyFlow.c                     SSK Jn  UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + U R                  S9$ )Nr   rI   )rY   rC   )rK   rJ   RemoteLoginWithAuthProxyFlowr[   r<   r;   r   r\   r]   r^   r_   r=   r`   s     r   r>   .RemoteLoginWithAuthProxyFlowRunner._CreateFlow   s]    >..AA'1'8'8'='=		wwy$)'' B ) )r   r   Nrb   r   r   r   rj   rj      s
    :	)r   rj   c                       \ rS rSrSrS rSrg)NoBrowserHelperRunner   z)A flow runner to run NoBrowserHelperFlow.c                 .   SSK Jn   UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9$ ! UR                   a    [        R                  " S5        e f = f)Nr   rI   rX   zCannot start a local server to handle authorization redirection. Please run this command on a machine where gcloud can start a local server.)rK   rJ   NoBrowserHelperFlowr[   r<   r;   r   r\   r]   r^   r_   LocalServerCreationErrorr   r0   r`   s     r   r>   !NoBrowserHelperRunner._CreateFlow   s    >
''::



,,)3):):)?)?  &+ ; , ,
 ** 	ii 3 4 	s   A#A, ,(Br   Nrb   r   r   r   rp   rp      s
    1r   rp   c                   "    \ rS rSrSrSrS rSrg) BrowserFlowWithOobFallbackRunner   z?A flow runner to try normal web flow and fall back to oob flow.zXThere was a problem with web authentication. Try running again with --no-launch-browser.c                 2   SSK Jn   UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9$ ! UR                   a  n[        R                  " U5        [        R                  " S5        UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9s S nA$ S nAff = f)Nr   rI   rX   z"Defaulting to URL copy/paste mode.)rK   rJ   FullWebFlowr[   r<   r;   r   r\   r]   r^   r_   rt   r   warningrZ   r@   rO   r*   s      r   r>   ,BrowserFlowWithOobFallbackRunner._CreateFlow   s    >,22



,,)3):):)?)?  &+ 3 , ,
 ** ,	kk!n	kk67^^..



,,)3):):)?)?  &+ / , ,,   A#A, ,D<BDDDr   Nr   r   r   r   r   rM   r>   r   r   r   r   rw   rw      s    GH,r   rw   c                   "    \ rS rSrSrSrS rSrg)&BrowserFlowWithNoBrowserFallbackRunner   zEA flow runner to try normal web flow and fall back to NoBrowser flow.zQThere was a problem with web authentication. Try running again with --no-browser.c                 2   SSK Jn   UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9$ ! UR                   a  n[        R                  " U5        [        R                  " S5        UR                  R                  U R                  U R
                  [        R                  R                  R                  R                  5       (       + S9s S nA$ S nAff = f)Nr   rI   rX   z Defaulting to --no-browser mode.)rK   rJ   rz   r[   r<   r;   r   r\   r]   r^   r_   rt   r   r{   rg   r|   s      r   r>   2BrowserFlowWithNoBrowserFallbackRunner._CreateFlow   s    >,22



,,)3):):)?)?  &+ 3 , ,
 ** ,	kk!n	kk45!!44



,,)3):):)?)?  &+ 5 , ,,r~   r   Nr   r   r   r   r   r      s    MA,r   r   c                     U (       a6  [         R                  " U 5       n[        R                  " U5      sSSS5        $ [	        5       $ ! , (       d  f       [	        5       $ = f)zECreates a client config from a client id file or gcloud's properties.N)r   
FileReaderjsonload+_CreateGoogleAuthClientConfigFromProperties)client_id_filefs     r   _CreateGoogleAuthClientConfigr     sC    			.	)QYYq\ 
*	)	4	66 
*	)	4	66s   A
Ac                  d   [         R                  R                  R                  R	                  SS9n [
        R                  " 5       n[         R                  R                  R                  R	                  SS9n[         R                  R                  R                  R	                  SS9nSUUU US.0$ )z1Creates a client config from gcloud's properties.T)requiredr   )	client_idclient_secretauth_uri	token_uri)	r   r\   r]   	auth_hostr2   r
   GetDefaultTokenUrir   r   )r   r   r   r   s       r   r   r     s    ##--1141@(&&()$$..22D2A)##((66::D:I- ( 	
 r   c                 @    U S   S   [         R                  [        4;   $ )Nr   r   )r   CLOUDSDK_CLIENT_ID%DEFAULT_CREDENTIALS_DEFAULT_CLIENT_ID)rB   s    r   _IsGoogleOwnedClientIDr   !  s*    

$[
1'')NOP Qr   c                 T   SSK Jn  SSKJn	  SSKJn
  U(       a  [        U5        U(       d  [        U5      nU(       d  0 n[        R                  " SS9nU(       a  [        X5      R                  " S0 UD6nOU(       a6  U(       d  U
R                  S5      e[        X5      R                  " SSU0UD6nOU(       a  [        XU5      R                  " S0 UD6nOrU(       dP  U(       a,  [        U5      (       d  [        X5      R                  " S0 UD6nO8[        XU5      R                  " S0 UD6nO[!        X5      R                  " S0 UD6nU(       aX  [#        XR$                  5      (       a!  SS	KJn  UR$                  R)                  U5      $ [#        XR$                  5      (       a  U$ g
g
)a  Launches a 3LO oauth2 flow to get google-auth credentials.

Args:
  scopes: [str], The list of scopes to authorize.
  client_id_file: str, The path to a file containing the client id and secret
    to use for the flow.  If None, the default client id for the Cloud SDK is
    used.
  client_config: Optional[Mapping], the client secrets and urls that should be
    used for the OAuth flow.
  no_launch_browser: bool, True if users specify --no-launch-browser flag to
    use the remote login with auth proxy flow.
  no_browser: bool, True if users specify --no-browser flag to ask another
    gcloud instance to help with authorization.
  remote_bootstrap: str, The auth parameters specified by --remote-bootstrap
    flag. Once used, it means the command is to help authorize another
    gcloud (i.e. gcloud without access to browser).
  query_params: Optional[Mapping], extra params to pass to the flow during
    `Run`. These params end up getting used as query
    params for authorization_url.
  auth_proxy_redirect_uri: str, The uri where OAuth service will redirect the
    user to once the authentication is complete for a remote login with auth
    proxy flow.
Returns:
  core.credentials.google_auth_credentials.Credentials, The credentials
    obtained from the flow.
r   ) external_account_authorized_user)credentialsrI   T)attempt_launch_browserzbCannot launch browser. Please run this command on a machine where gcloud can launch a web browser.partial_auth_url)google_auth_credentialsNr   )google.authr   google.oauth2r   rK   rJ   !AssertClientSecretIsInstalledTyper   r   ShouldLaunchBrowserrd   rL   WebBrowserInaccessiblerp   rj   r   r   r&   Credentialsr   FromGoogleAuthUserCredentials)rA   r   rB   no_launch_browser
no_browserremote_bootstrapquery_paramsauth_proxy_redirect_urir   oauth2_credentialsrO   can_launch_browser
user_credsc_google_auths                 r   #DoInstalledAppBrowserFlowGoogleAuthr   &  s   F ;=< %n5	1.AM	L$88!#$V;??O,OJ))34 4 'v=AA ;);-9;J36	c
 J  4]CC&v=AA j 6
!8 j 8"s# 3%13J*<<== [&&DDZPP*JJKK L r   c                    Sn [         R                  " [        R                  " U 5      5      n[        U5      S:w  a  [        SU 35      e[        U5      S   nU[        :w  a  [        S	[         S
U SU 35      eg! [        R                   a    [        SU  S35      e[         R                   a    [        SU  SU 35      ef = f)zDAssert that the file is a valid json file for installed application.zTo obtain a valid client ID file, create a Desktop App following the steps outlined in https://support.google.com/cloud/answer/6158849?hl=en#zippy=%2Cnative-applications%2Cdesktop-apps.zCannot read file: "z".zClient ID file z is not a valid JSON file.    zNExpected a JSON object with a single property for an "installed" application. r   zOnly client IDs of type 'z%' are allowed, but encountered type 'z'. N)
r   loadsr   ReadFileContentsr   r   JSONDecodeErrorlentupleCLIENT_SECRET_INSTALLED_TYPE)r   actionable_messageobjclient_types       r   r   r   ~  s    l 

**U++N;
<C 	X]
#	+,	.  c
1+00
#
#$@#A B""-c2D1E	G  1 
 N
#&9.9I$L
MM			 
#
.) *	! s   *A< <ACc                    [         R                  R                  R                  R	                  5       nX :X  a  g[
        R                  " S5      R                  XU5      n[        R                  " US9nU(       aY  [         R                  " [         R                  R                  R                  U 5        [        R                  R                  S5        gg)a?  Prompt the user to update the universe domain if there is conflict.

If the given universe domain is different from the core/universe_domain
property, prompt the user to update the core/universe_domain property.

Args:
  new_universe_domain: str, The given new universe domain.
  account: str, The account name to use.
Nz        WARNING: This account [{0}] is from the universe domain [{1}],
        which does not match the current core/universe property [{2}].

        Do you want to set property [core/universe_domain] to [{1}]? [Y/N]
        )messagez(Updated property [core/universe_domain].)r   r\   coreuniverse_domainr2   textwrapdedentr$   r	   PromptContinuePersistPropertyr   statusPrint)new_universe_domainaccountcurrent_universe_domainr   should_update_universe_domains        r   HandleUniverseDomainConflictr     s     '--22BBFFH3
OO   VG2IJ	 

 #-";";G"L"..0C JJ?@	 #r   r:   )NNFFNNN)1r   rQ   r   r   googlecloudsdk.command_lib.utilr   r.   r   r   r   r   r   googlecloudsdk.core.consoler	   rK   r
   googlecloudsdk.core.utilr   sixr   )DEFAULT_CREDENTIALS_DEFAULT_CLIENT_SECRETCLOUD_PLATFORM_SCOPESQL_LOGIN_SCOPEGOOGLE_DRIVE_SCOPEUSER_EMAIL_SCOPEOPENIDDEFAULT_SCOPESr   r   r   r   r+   r5   with_metaclassABCMetaobjectr7   rT   rd   rj   rp   rw   r   r   r   r   r   r   r   r   r   r   <module>r      sO    *    9 & * # * $ 2 1 * 

 )s %,F )G D< C 	 	  + J 
 
 
 F ##CKK8 @*J *** *) )J (,z ,4,Z ,47"Q 8<6::?389=59@DUp:Ar   