如何为 UWP 应用程序为 Google 提供程序创建自定义 OAuth 2.0 redirect_uri? [英] How to create a custom OAuth 2.0 redirect_uri for Google provider, for UWP app?

查看:14
本文介绍了如何为 UWP 应用程序为 Google 提供程序创建自定义 OAuth 2.0 redirect_uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to register a custom redirect_uri (like pw.oauth2:/oauth2redirect) in Google Developer console for a native application (this is the recommended approach for UWP apps). According to https://developers.google.com/identity/protocols/OAuth2InstalledApp#request-parameter-redirect_uri, there must be an option to select "Custom URI scheme (Android, iOS, UWP)" but I only see these options:

  • 网络应用程序
  • 安卓
  • iOS
  • 其他

选择其他不会让我指定redirect_uri.

Selecting Other does not let me specify redirect_uri.

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

How am I supposed to register a custom redirect_uri for a UWP app?

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

If I don't register a redirect_uri, I'm getting redirect_uri_mismatch error during OAuth authorization process.

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

The ClientID in this github sample https://github.com/googlesamples/oauth-apps-for-windows/tree/master/OAuthUniversalApp works. Looks like for this ClientID the required_uri registered. But how to achieve the same for my own ClientIDs?

这个老问题讨论了类似的问题,但也从未得到答复:适用于 UWP 的 Google API 与自定义重定向不兼容方案

This old question discusses something similar but it has never been replied either: 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.

To clarify. I'm using the Google sample mentioned above (https://github.com/googlesamples/oauth-apps-for-windows/tree/master/OAuthUniversalApp). It works with hardcoded ClientID provided by Google. I just can't get it working with my own ClientID as I see no way to register my own redirect_uri in their Developer Console.

推荐答案

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

Got it (after some trial and error). In Google Developer Console, you need to create iOS app. In app properties, you need to specify the URL scheme (taken from Package Manifest / Declarations / Protocol / Name of UWP app project in Visual Studio) in Bundle ID parameter.

AppStore ID 和 Team ID 可以保留为空.

AppStore ID and Team ID can remain empty.

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

The Bundle ID acts as a URL scheme. In my case, I specified pw.oauth2 value (it's the value in Google sample). Then I saved changes, set ClientID of iOS app in the Google UWP sample and found that everything is working properly now.

Google 控制台在 iOS 应用属性中提供 iOS 网址方案参数(类似于 com.googleusercontent.apps.6284700xxxxx-6tp4d3xxxxx).忽略 UWP 应用的此值.只有 Bundle ID 很重要.

Google Console provides iOS URL scheme parameter in iOS app properties (something like com.googleusercontent.apps.6284700xxxxx-6tp4d3xxxxx). Ignore this value for a UWP app. Only Bundle ID matters.

这篇关于如何为 UWP 应用程序为 Google 提供程序创建自定义 OAuth 2.0 redirect_uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆