【问题标题】:Error while trying to authenticate with `gcloud init`尝试使用“gcloud init”进行身份验证时出错
【发布时间】:2022-06-20 19:06:09
【问题描述】:

我正在尝试使用:gcloud init 验证 gcloud sdk。

我得到了一个我应该访问的 URL,以便复制令牌并将其返回到 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 后立即出现此错误。

【问题讨论】:

  • 您是否在浏览器中收到此错误?如果是,请清除浏览器 cookie 并重新启动计算机。
  • 您在定义 GoogleStrategy 时是否考虑过,JSON 键必须是 callbackURL 而不是 this post 中建议的 callbackUrl(即大写 URL)?
  • @OsvaldoLópez 不确定 JSON 密钥和谷歌策略是什么意思,安装 gcloud sdk 后立即发生此错误...gcloud init 之前没有配置
  • 您还有这个问题吗?运行 gcloud auth login 时会发生什么?您也可以尝试通过删除:浏览器 cookie、DNS 缓存和禁用浏览器扩展来解决它。此外,您可以尝试 gcloud init --no-browser。此标志阻止命令启动浏览器进行授权。
  • 您可以查看this post 和此forum thread 以了解与 WSL 相关的一些故障排除。请让我知道它们是否适合您。另一方面,您能否为社区更新您的帖子:1. 添加 wsl-2 标签,2. 提到您正在尝试运行 gcloud init从它,以及 3. 安装 gcloud sdk 后立即发生此错误?

标签: google-cloud-platform oauth-2.0 gcloud windows-subsystem-for-linux wsl-2


【解决方案1】:

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

运行 gcloud auth login,然后将整个输出(不仅仅是 URL)复制到同时安装了 Web 浏览器和 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"

当您在具有网络浏览器的计算机上运行它时,它将打开一个浏览器窗口并提示您登录。在网络浏览器中授权您的应用程序后,您会在终端中获得一个新 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

【讨论】:

  • 谢谢,成功了。但我有不同的反应。凭据保存到文件:[/home/developer/.config/gcloud/application_default_credentials.json] 这些凭据将被任何请求应用程序默认凭据 (ADC) 的库使用
【解决方案2】:

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

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

Here你可以找到一些可能有用的 Google 群组相关主题。

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

【讨论】:

  • @Imad 这个或其他答案对你有用吗?
【解决方案3】:

试试

gcloud init --console-only

然后您将获得有效的网址。

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....

2022 年 6 月 20 日更新。对于版本 389.0.0,选项 console-only 已删除。 所以改为使用

gcloud init --no-browser

【讨论】:

    猜你喜欢
    • 2015-12-25
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2019-12-21
    • 2013-05-23
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多