尝试使用“gcloud init”进行身份验证时出错

Error while trying to authenticate with `gcloud init`

我正在尝试使用以下方法验证 gcloud sdk:gcloud init

我得到一个 URL 我应该访问以复制令牌并将其 return 复制到 CLI...但是我得到的不是令牌,而是这个错误 :

Erreur d'autorisation
Erreur 400 : invalid_request
Missing required parameter: redirect_uri

这是一个错误吗?

gcloud version 信息:

Google Cloud SDK 377.0.0
alpha 2022.03.10
beta 2022.03.10
bq 2.0.74
bundled-python3-unix 3.8.11
core 2022.03.10
gsutil 5.8

我在 wsl2 (Ubuntu 18.04) 运行 gcloud init。使用 sudo apt install google-cloud-sdk.

安装 gcloud 后立即发生此错误

我遇到了同样的问题,gcloud 稍微改变了他们的身份验证流程的工作方式。

运行 gcloud auth login 然后将整个输出(不仅仅是 URL)复制到同时安装了网络浏览器和 gcloud CLI 的计算机上的终端。您应该复制的命令看起来像

gcloud auth login --remote-bootstrap="https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=****.apps.googleusercontent.com&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=****&access_type=offline&code_challenge=****&code_challenge_method=S256&token_usage=remote"

当你 运行 在你有网络浏览器的电脑上时,它会打开浏览器 window 并提示你登录。一旦你在网络浏览器中授权你的应用程序,你就会得到一个新的 URL 在你的终端看起来像

https://localhost:8085/?state=****&code=****&scope=email%20openid%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/cloud-platform%20https://www.googleapis.com/auth/appengine.admin%20https://www.googleapis.com/auth/compute%20https://www.googleapis.com/auth/accounts.reauth&authuser=0&hd=****&prompt=consent

Enter the output of the above command: 之后将这个新的 URL 粘贴回无头机器的提示符中(在您的情况下,这将在您的 WSL2 终端中)。按回车,你得到输出

You are now logged in as [****].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID
[8]+  Done                    code_challenge_method=S256

有一些解决方法,它们 取决于您的特定 Windows 环境。

this post and in 中,您可以查看 WSL 中与 gcloud 运行 相关的最相关问题。

Here 您可以找到一些 Google 组相关的主题可能会有帮助。

最后,您可以查看一些相关的 Windows troubleshootings,它们可以帮助解决您自己环境中与 WSL2 相关的问题。

尝试

gcloud init --console-only

然后你会得到 url 会起作用。

You must log in to continue. Would you like to log in (Y/n)?  y                                                                                                                                                                                                                                                                                                                                                                                                                       
WARNING: The --[no-]launch-browser flags are deprecated and will be removed on June 7th 2022 (Release 389.0.0). Use --no-browser to replace --no-launch-browser.                                                                                                                                                                                                                                                                                                                      
Go to the following link in your browser:                                                                                                                                                                                                                                                                                                                                                                                                                                                 

https://accounts.google.com/o/o....