oAuth2 Google API 中的错误 - invalid_request“您无法登录此应用程序,因为它不符合 Google 的 OAuth 2.0 政策”

问题描述 投票:0回答:1

我在 Google 云中有一个项目,并为其创建了一个 oauth2 客户端(Web 应用程序)。正如 Google 文档中提到的 using oAuth2 我首先发送了一个 HTTP GET 来获取授权码。

https://accounts.google.com/o/oauth2/v2/auth?scope=<my_scope>&access_type=offline&include_granted_scopes=true&response_type=code&state=state_parameter_passthrough_value&redirect_uri=https%3A//localhost%3A7082/signin-google&flowName=GeneralOAuthFlow&client_id=<my_client_id>

此步骤似乎工作正常,因为我获得了与我请求的相同范围的授权代码。

下一步我将发送授权代码以获取访问令牌

POST https://oauth2.googleapis.com/token
code:<code_retrieved_from_previous_step>
client_id:<my_client_id>
client_secret:<my_client_secret>
redirect_uri:https%3A//localhost%3A7082/signin-google
grant_type:authorization_code

总是失败并出现以下错误:

{
  "error": "invalid_request",
  "error_description": "\nYou can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy for keeping apps secure.\n\nYou can let the app developer know that this app doesn't comply with one or more Google validation rules.\n  "
}

有几点需要注意:

  1. 我的项目仍处于“测试”阶段,我想品牌检查、验证等事情现在可以暂停。我仅使用测试用户登录。
  2. 我尝试创建一个新项目和一组新的
    client_id
    client_secret
    ,但错误仍然存在。
  3. 我还经历了不久前进行的 OOB 弃用,但我认为它不会影响 Web 应用程序。
  4. 我尝试了使用 JSON 负载和 url_encoded 格式的
    /token
    步骤,但结果是相同的

我不明白这里违反了哪项政策。有没有办法了解这里的根本原因?

oauth-2.0 google-oauth
1个回答
0
投票

您似乎在不应该对 POST 请求中的重定向 URL 进行 URL 编码。

虽然 POST 数据确实可以使用

application/x-www-form-urlencoded
内容类型,但 URL 编码通常由您用于发送请求的库进行。如果您对其进行编码,则会导致问题,导致 URL 被破坏并且与 Google 端的配置不匹配。

© www.soinside.com 2019 - 2024. All rights reserved.