首页 > 解决方案 > 如何为 Google 提供商、UWP 应用程序创建自定义 OAuth 2.0 redirect_uri?

问题描述

我想在 Google Developer 控制台中为原生应用程序注册一个自定义 redirect_uri(如 pw.oauth2:/oauth2redirect)(这是 UWP 应用程序的推荐方法)。根据https://developers.google.com/identity/protocols/OAuth2InstalledApp#request-parameter-redirect_uri,必须有一个选择“自定义 URI 方案(Android、iOS、UWP)”的选项,但我只看到这些选项:

选择其他不允许我指定redirect_uri。

我应该如何为 UWP 应用注册自定义 redirect_uri?

如果我没有注册 redirect_uri,我会在 OAuth 授权过程中收到 redirect_uri_mismatch 错误。

此 github 示例https://github.com/googlesamples/oauth-apps-for-windows/tree/master/OAuthUniversalApp中的 ClientID有效。看起来这个 ClientID 是 required_uri 注册的。但是如何为我自己的 ClientID 实现相同的目标?

这个老问题讨论了类似的问题,但也从未得到答复: Google APIs for UWP not playing nice with custom redirect scheme

编辑:澄清。我正在使用上面提到的 Google 示例(https://github.com/googlesamples/oauth-apps-for-windows/tree/master/OAuthUniversalApp)。它适用于 Google 提供的硬编码 ClientID。我只是无法使用我自己的 ClientID 来使用它,因为我看不到在他们的开发者控制台中注册我自己的 redirect_uri 的方法。

标签: uwpoauth-2.0google-oauth

解决方案


明白了(经过反复试验)。在 Google Developer Console 中,您需要创建 iOS 应用。在应用程序属性中,您需要在 Bundle ID 参数中指定 URL 方案(取自Visual Studio 中的包清单/声明/协议/UWP 应用程序项目的名称)。

AppStore ID 和 Team ID 可以留空。

Bundle ID 充当 URL 方案。就我而言,我指定了 pw.oauth2值(它是 Google 示例中的值)。然后我保存了更改,在 Google UWP 示例中设置了 iOS 应用的 ClientID,发现现在一切正常。

Google 控制台在 iOS 应用程序属性中提供了iOS URL 方案参数(类似于com.googleusercontent.apps.6284700xxxxx-6tp4d3xxxxxx)。对于 UWP 应用,请忽略此值。只有 Bundle ID 很重要。


推荐阅读