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

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

问题描述

我想在Google Developer Console中为本机应用程序注册一个自定义的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:

  • Web应用程序
  • Android
  • Chrome
  • 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和团队ID可以保留为空.

AppStore ID and Team ID can remain empty.

Bundle 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应用属性(例如 com.googleusercontent.apps.6284700xxxxx-6tp4d3xxxxx 之类)中提供了 iOS URL方案参数.忽略UWP应用的此值.仅捆绑包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天全站免登陆