1

我正在尝试通过本机 Mac 应用程序向 Google OAuth 2 进行身份验证。我在 Google Developer Console 中将我的应用程序设置为Desktop应用程序,但无处指定redirect_uri. 据我了解,这些仅适用于 Web 应用程序。

但是在使用 Swift 编写我的请求时ASWebAuthenticationSession,我得到的身份验证 URL 是这样的(为易读添加了换行符):

https://accounts.google.com/o/oauth2/v2/auth?
client_id=******.apps.googleusercontent.com&
response_type=code&
redirect_uri=pro.cova%3A%2F&
scope=profile%2520email%2520https%3A%2F%2Fmail.google.com%2F&flowName=GeneralOAuthFlow

我的应用的自定义 URL 类型是pro.cova:/.

我从 Google 收到此错误:

Error 400: redirect_uri_mismatch

如果 Google Developer Console 中没有指定不匹配,可能会发生什么不匹配?

4

1 回答 1

0

事实证明,在构建原生 Mac 应用程序时,您必须在 Google Developer Console 中创建“iOS”API 凭据。设置时,您必须像这样指定捆绑 ID:pro.cova

当您redirect_uri在请求中设置时,它的末尾ASWebAuthenticationSession必须有一个,如下所示::/redirect_uri=pro.cova:/

但是callbackURLSchemein your ASWebAuthenticationSessionis 没有 the :/so it's just pro.cova

我希望 Google 的 API 文档对 API 凭证选项说“iOS 或 Mac”。

于 2022-02-14T16:13:48.167 回答