uwp - 如何为 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)”的选项,但我只看到这些选项:
- Web应用程序
- 安卓
- 铬合金
- iOS
- 其他
选择其他不允许我指定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 的方法。
解决方案
明白了(经过反复试验)。在 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 很重要。
推荐阅读
- android - 微调器下拉列表显示在微调器小部件下方
- rxjs - RxJS 中是否有类似 flatTap 的东西
- sql - SQL - 通过条件选择的键获取唯一值
- python - 按日期分组并添加具有最小值的新列 - 熊猫
- python - 为什么在for循环的每一步都分配给l
- npm - 为什么 npm 安装包会创建一个指向父目录的节点模块?
- maven-surefire-plugin - 如何通过命令行传递 maven-surefire-plugin 参数
- php - 我正在尝试从 github hexters coinpayment 安装 Coinpayment srcipt,但我在 Laravel 中遇到了障碍
- python - bulk_update_or_create 选项在 Django 中可用吗?
- django - NoReverseMatch at /products/“将产品添加到购物篮”