
    )                     4   S 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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 \RB                   " S S\RD                  5      5       r#g)zKA command that prints an access token for Application Default Credentials.
    )absolute_import)division)unicode_literals)credentials)
exceptions)impersonated_credentials)util)arg_parsers)base)log)
properties)requests)creds)google_auth_credentials)storeNi  c                   .    \ rS rSrSr\S 5       rS rSrg)PrintAccessToken+   a5  Print an access token for your current Application Default Credentials.

{command} generates and prints an access token for the current
Application Default Credential (ADC). The
[ADC](https://google.aip.dev/auth/4110) can be specified either by using
`gcloud auth application-default login`,
`gcloud auth login --cred-file=/path/to/cred/file --update-adc`, or by
setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.

The access token generated by {command} is useful for manually testing
APIs via curl or similar tools.

In order to print details of the access token, such as the associated account
and the token's expiration time in seconds, run:

  $ curl -H "Content-Type: application/x-www-form-urlencoded" \
  -d "access_token=$(gcloud auth application-default print-access-token)" \
  https://www.googleapis.com/oauth2/v1/tokeninfo

Note that token itself may not be enough to access some services.
If you use the token with curl or similar tools, you may see
permission errors similar to "Your application has authenticated using end
user credentials from the Google Cloud SDK or Google Cloud Shell".
If it happens, you may need to provide a quota project in the
"X-Goog-User-Project" header. For example,

  $ curl -H "X-Goog-User-Project: your-project" \
      -H \
      "Authorization: Bearer $(gcloud auth application-default \
   print-access-token)" foo.googleapis.com

The identity that granted the token must have the serviceusage.services.use
permission on the provided project. See
https://cloud.google.com/apis/docs/system-parameters for more
information.
c                 H   U R                  S[        R                  " SS9SS9  U R                  S[        R                  " SS9S	S
R	                  SR                  [        SR                  [        R                  5      5      5      S9  U R                  R                  S5        g )N
--lifetime43200s)upper_bounda  Access token lifetime. The default access token lifetime is 3600 seconds, but you can use this flag to reduce the lifetime or extend it up to 43200 seconds (12 hours). The org policy constraint `constraints/iam.allowServiceAccountCredentialLifetimeExtension` must be set if you want to extend the lifetime beyond 3600 seconds. Note that this flag is for service account impersonation only, so it only works when either `--impersonate-service-account` flag or `auth/impersonate_service_account` property is set.)typehelp--scopes   )
min_lengthSCOPEam  The scopes to authorize for. This flag is supported for user accounts and service accounts only. The list of possible scopes can be found at: [](https://developers.google.com/identity/protocols/googlescopes).

For end-user accounts, the provided scopes must be from [{0}], or the scopes previously specified through `gcloud auth application-default login --scopes`., `{}`)r   metavarr   zvalue(token))add_argumentr
   DurationArgListformatjoinmap	auth_utilDEFAULT_SCOPESdisplay_info	AddFormat)parsers    :lib/surface/auth/application_default/print_access_token.pyArgsPrintAccessToken.ArgsR   s    
!!h7	C	      A.< =CF499y778D: =;  < !!.1    c                 Z    [         R                  " 5       R                  UR                  =(       d    [        R
                  /S9u  p#[         R                  " U5      n[        R                   R"                  R$                  R'                  5       nU=(       d    USLnUR(                  (       a  U(       d  [        R*                  " SS5      eU(       a  [,        R.                  " U5      u  pUR                  (       a  U(       d  [         R0                  R3                  U5      n
U
[         R0                  R4                  [         R0                  R6                  4;  a/  [        R8                  " SR;                  U
R<                  5      5        UR                  [        R>                  [        R@                  /-   n[C        U[D        RF                  5      (       a  URI                  U5      nOXl%        [C        U[L        RN                  5      (       a  [P        RN                  RS                  U5      nU(       a7  U(       a  WUl*        W	Ul+        UR(                  (       a  UR(                  Ul,        [         RZ                  " 5       Ul.        [^        R`                  " 5       n [,        Rb                  " SS9   URe                  U5        SSS5        U(       a  U(       a  U$ [p        RN                  " UWW	UR                  =(       d    [        R
                  /UR(                  =(       d    [r        S9nURe                  U5        U$ ! [        R                   aD  n[        R                  " USS9  [        R                  " [        R                  " U5      5      eSnAff = f! , (       d  f       N= f! [f        Rh                   ao  nUR                  (       aW  [        R*                  " S	S
R;                  SRk                  [m        SR:                  [        Rn                  5      5      5      5      eUeSnAff = f)zRun the helper command.)scopesT)exc_infoNr   a  Lifetime flag is for service account impersonation only. It must be used together with either --impersonate-service-account flag or auth/impersonate_service_account property, or the application default credential json file must have `impersonated_service_account` type.zQ`--scopes` flag may not work as expected and will be ignored for account type {}.)for_adcr   zInvalid scopes value. Please make sure the scopes are from [{0}], or the scopes previously specified through `gcloud auth application-default login --scopes`.r   r    )source_credentialstarget_principal	delegatestarget_scopeslifetime):c_credsGetGoogleAuthDefaultdefaultr2   r(   CLOUD_PLATFORM_SCOPEgoogle_auth_exceptionsDefaultCredentialsErrorr   debugc_excToolExceptionsix	text_type IsImpersonatedAccountCredentialsr   VALUESauthimpersonate_service_accountGetr9   InvalidArgumentExceptionc_storeParseImpersonationAccountsCredentialTypeGoogleAuthFromCredentialsUSER_ACCOUNTSERVICE_ACCOUNTwarningr%   keyOPENIDUSER_EMAIL_SCOPE
isinstancer   Scopedwith_scopes_scopesgoogle_auth_credsCredentialsc_google_authFromGoogleAuthUserCredentials_target_principal
_delegates	_lifetimeGetDefaultTokenUri
_token_urir   GoogleAuthRequest'HandleGoogleAuthCredentialsRefreshErrorrefreshcreds_exceptionsTokenRefreshErrorr&   r'   r)   r   _DEFAULT_TOKEN_LIFETIME_SECS)selfargsr   _eis_adc_cred_impersonatedimpersonation_service_accountsis_impersonation_usedr6   r7   	cred_typer2   reqimpersonated_credss                 r-   RunPrintAccessToken.Runr   s7   2--/77@!?!? @ 8 Bhe   'GGN::>>@ # 5 &d2  }}2**
6	 	 &&-&H&H
('# {{022BB5Ii	

*
*
7
7

*
*
:
: 

 	##)6)--#8	
 {{i..	0J0JKKf 
E;--	.	.!!&) %*6677''EE
e	'"2$	--
 113E 
$
$
&C::4Hc I$ !$<l1== )kkEi&D&D%E>"> s#g "99 2	iiD!a 0112n IH-- 		,,@ VDIIc&--1I1IJKLN 	N 	sO   AL; N' -N?N' ;N?NN
N$ N' $N' 'P*;A*P%%P* N)	__name__
__module____qualname____firstlineno____doc__staticmethodr.   rr   __static_attributes__rt   r0   r-   r   r   +   s"    #J 2 2>yr0   r   )$ry   
__future__r   r   r   google.authr   r   r>   r   google.oauth2rY   googlecloudsdk.api_lib.authr	   r(   googlecloudsdk.callioper
   r   rA   googlecloudsdk.corer   r   r   googlecloudsdk.core.credentialsr   r:   re   r   r[   r   rK   rC   rg   UniverseCompatibleCommandr   rt   r0   r-   <module>r      ss     '  ' # < 0 : 9 / ( 7 # * ( < J T < 
#  t||  r0   