且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

"gcloud auth应用程序默认登录"之间的区别和"gcloud auth login"

更新时间:2023-10-27 20:00:40

不同之处在于用例:

作为开发人员,我想通过gcloud与GCP进行交互.
gcloud auth login
这将获取您的凭据并将其存储在~/.config/gcloud/中.现在,您可以从终端运行gcloud命令,它将自动找到您的凭据.在这种情况下,任何代码/SDK都会不会自动获取您的信誉.

As a developer, I want to interact with GCP via gcloud.
gcloud auth login
This obtains your credentials and stores them in ~/.config/gcloud/. Now you can run gcloud commands from your terminal and it will find your credentials automatically. Any code/SDK will not automatically pick up your creds in this case.

参考: https://cloud.google.com/sdk/gcloud/参考/身份验证/登录

作为开发人员,我希望我的代码通过SDK与GCP交互.
gcloud auth application-default login
这将通过网络流获取您的凭据,并将其存储在应用程序默认凭据的众所周知位置" 中.现在,您运行的任何代码/SDK都将能够自动找到凭据.当您要本地测试通常在服务器上运行并使用服务器端凭据文件的代码时,这是一个很好的替代方法.

As a developer, I want my code to interact with GCP via SDK.
gcloud auth application-default login
This obtains your credentials via a web flow and stores them in 'the well-known location for Application Default Credentials'. Now any code/SDK you run will be able to find the credentials automatically. This is a good stand-in when you want to locally test code which would normally run on a server and use a server-side credentials file.

参考: https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login

编辑(09/19/2019):
正如肯特(Kent)在下面的评论中所做的贡献,"是位于本地~/.config/gcloud/目录中的名为application_default_credentials.json的文件.我在下面的 Theodore Sui Daniel De Leo 的文章中添加了一个附加链接,其中更详细地介绍了差异身份验证方法.

Edit (09/19/2019):
As Kent contributed in his comment below, 'the well-known location for Application Default Credentials' is a file named application_default_credentials.json located in your local ~/.config/gcloud/ directory. I've added an additional link below to an article by Theodore Sui and Daniel De Leo which goes into greater detail about the difference authentication methods.

文章: https://medium.com/google-cloud /local-remote-authentication-with-google-cloud-platform-afe3aa017b95