1

I am trying to authenticate to Google OAuth 2 via a native Mac app. I set up my app in the Google Developer Console as a Desktop application, and there is nowhere to specify a redirect_uri. As I understand it, those are only available to web applications.

But in composing my request in Swift using ASWebAuthenticationSession, my resulting authentication URL is like this (line breaks added for legibility):

https://accounts.google.com/o/oauth2/v2/auth?
client_id=******.apps.googleusercontent.com&
response_type=code&
redirect_uri=pro.cova%3A%2F&
scope=profile%2520email%2520https%3A%2F%2Fmail.google.com%2F&flowName=GeneralOAuthFlow

My app's custom URL type is pro.cova:/.

I'm getting this error from Google:

Error 400: redirect_uri_mismatch

What mismatch could be happening if there isn't one specified in the Google Developer Console?

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128

1 Answers1

2

It turns out that when building a native Mac app, you have to create "iOS" API credentials in the Google Developer Console. When setting it up, you have to specify your bundle ID like this: pro.cova

When you set the redirect_uri in your ASWebAuthenticationSession request, it must have a :/ at the end like this: redirect_uri=pro.cova:/

But the callbackURLScheme in your ASWebAuthenticationSession is without the :/ so it's just pro.cova.

I wish Google's API docs said "iOS or Mac" for the API credential options.

Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128