
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ	 ddl
mZ ddlmZ dd	lmZ d
ZdZdZdZdZdZddZd Zd Zy)z3Support library for the login-config auth commands.    )absolute_import)division)unicode_literals) external_account_authorized_user)util)
exceptions)config)
propertiesCLOUDSDK_AUTH_LOGIN_CONFIG_FILEzcloud.googlez&https://sdk.cloud.google/authcode.htmlzhttps://sdk.{}/authcodez8https://sdk.cloud.google/applicationdefaultauthcode.htmlz)https://sdk.{}/applicationdefaultauthcodec                     t        j                  |       }|j                  dd      dk7  rt        j                  d      t        ||      }|d   }|j                  d      }d}|dk7  r||dz   d }|j                  d	d      }|sV|j                  d
d      }	|	r	|	t        k(  r|r
t        |d	<   n-t        |d	<   n#|rt        }
nt        }
|
j                  |	      |d	<   t        j                  t        j                  f|d|id|}t!        |t"        j$                        rM|j                  dd      }|xs2 t&        j(                  j*                  j,                  j/                         |_        |j2                  s||_        |S )a  DoWorkforceHeadfulLogin attempts to log in with appropriate login configuration.

  It will return the account and credentials of the user if it succeeds

  Args:
    login_config_file (str): The path to the workforce headful login
      configuration file.
    is_adc (str): Whether the flow is initiated via application-default login.
    **kwargs (Mapping): Extra Arguments to pass to the method creating the flow.

  Returns:
    (google.auth.credentials.Credentials): The account and
    credentials of the user who logged in
  typeN-external_account_authorized_user_login_configzOnly external account authorized user login config JSON credential file types are supported for Workforce Identity Federation login configurations.audiencez/locations/   auth_proxy_redirect_uriuniverse_cloud_web_domainprovider_name)client_configquery_paramsuniverse_domain)	auth_utilGetCredentialsConfigFromFilegetcalliope_exceptionsBadFileException_MakeThirdPartyClientConfigfindGOOGLE_DEFAULT_CLOUD_WEB_DOMAINADC_AUTH_PROXY_URL_GDUAUTH_PROXY_URL_GDU#ADC_AUTH_PROXY_URL_TEMPLATE_NON_GDUAUTH_PROXY_URL_TEMPLATE_NON_GDUformat#DoInstalledAppBrowserFlowGoogleAuthr	    CLOUDSDK_EXTERNAL_ACCOUNT_SCOPES
isinstancer   Credentialsr
   VALUEScorer   Get_universe_domainr   	_audience)login_config_fileis_adckwargslogin_config_datar   r   
path_startr   r   r   templatecredsuniverse_domain_from_configs                =lib/googlecloudsdk/command_lib/auth/workforce_login_config.pyDoWorkforceHeadfulLoginr7   (   s     <<=NOdFG

.
.	 
 ..?H-z*(}}]+*-2
 Z!^_-M #JJ'@$G	  1 5 5#T! &$(GG	,B(),>()	62*2//
#+f&' 
7
7--! = 	% 7CCD"3"7"78I4"P 	$ 	8!!11557 
 
EO	,    c                  f    t         j                  j                  j                  j	                         S )a>  _GetWorkforceLoginConfig gets the correct Credential Configuration.

  It will first check from the supplied argument if present, then from an
  environment variable if present, and finally from the project settings, if
  present.

  Returns:
    Optional[str]: The name of the Credential Configuration File to use.
  )r
   r)   authr.   r+    r8   r6   GetWorkforceLoginConfigr<   z   s%     
					1	1	5	5	77r8   c           
      t    t         j                  }t         j                  }d||| d   | d   | d   | d   d|diS )N	installedauth_url	token_urltoken_info_urlr   T)	client_idclient_secretauth_uri	token_urirA   r   3pir/   )r	   CLOUDSDK_CLIENT_IDCLOUDSDK_CLIENT_NOTSOSECRET)r1   r/   rB   rC   s       r6   r   r      sY    '')44- ('
3(5-.>? (
3
 r8   N)F)__doc__
__future__r   r   r   google.authr   googlecloudsdk.api_lib.authr   r   googlecloudsdk.callioper   r   googlecloudsdk.corer	   r
   r   r   r!   r#   r    r"   r7   r<   r   r;   r8   r6   <module>rO      s]     : &  ' 8 9 E & *"C "0 = "; >  0 $
Od8 r8   