请求中的重定向 URI http://localhost:8080/ 与 OAuth 客户端授权的不匹配

The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client

我正在尝试组织对 Google 广告的访问 API。

我卡在了第 3 步:https://developers.google.com/google-ads/api/docs/client-libs/python/oauth-web#step_3_-_generating_a_refresh_token

即获取刷新令牌。

我这样做:

$ ./authenticate_in_web_application.py --client_secrets_path=/path/to/secrets.json

secrets.json

{
    "web": {
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "client_id": "some_client_id",
        "client_secret": "i_m_so_secret",
        "javascript_origins": [
            "https://avtomotokniga.ru"
        ],
        "project_id": "smpt-auth",
        "redirect_uris": [
            "https://avtomotokniga.ru/"
        ],
        "token_uri": "https://oauth2.googleapis.com/token"
    }
}

当脚本运行时,它为我提供了一个 hyperlink。我按照 link 找到这个:

Error 400: redirect_uri_mismatch
The redirect URI in the request, http://localhost:8080/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/secret-uvml458ip15qmarbruq83bkmfbu3vilf.apps.googleusercontent.com?project=secret

问题

localhost:8080取自哪里?

我仔细检查了 secrets.json 和凭据页面 (https://console.developers.google.com/apis/credentials)。

重定向 URI 肯定存在:

并且它被保存了。我多次打开和关闭该页面。并下载 json 文件,即肯定会考虑重定向 URI。

如何定位问题?

根据您的屏幕截图,它不在那里。 在您的控制台上,我在重定向列表中只看到 https://avtomotokniga.ru/

您需要点击底部的“添加 URI”按钮并在那里添加 localhost:8080。

如果您没有明确指定 returnURL,Google 提供默认值“/google-signin”。

在 .NET 中,startup.auth.cs 文件中,将 URL 添加为

//google OAuth 2.0 Client IDs 
app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
{
    ClientId = "456545-r6k8kf3gffghpoh13212s1fnkkfe.apps.googleusercontent.com",
    ClientSecret = "VWuu45654655IeNUDEw32",
    CallbackPath = new PathString("/CONTROLLER/ExternalLoginCallbackFUNCTION")
});