1
votes

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 application
  • Android
  • Chrome
  • iOS
  • Other

Selecting Other does not let me specify redirect_uri.

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

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

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?

This old question discusses something similar but it has never been replied either: Google APIs for UWP not playing nice with custom redirect scheme

EDIT: 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.

2

2 Answers

2
votes

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 and Team ID can remain empty.

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 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.

0
votes

Two thoughts:

Are you trying to use WebAuthenticationBroker in UWP to prompt a user to sign in? In which case you can't customize your redirect_uri in UWP... it must be gotten from WebAuthenticationBroker.GetCurrentApplicationCallbackUri() which represents your Package SID... Looks something like this: ms-app://s-1-15-2-1374842229...

and

Make sure you're properly encoding and decoding your redirect_uri- it will mismatch if you do this wrong. Without your code it's hard to tell how you're doing this.

WebUtility.UrlEncode(redirectURI);