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?
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.covaWhen you set the
redirect_uriin yourASWebAuthenticationSessionrequest, it must have a:/at the end like this:redirect_uri=pro.cova:/But the
callbackURLSchemein yourASWebAuthenticationSessionis without the:/so it's justpro.cova.I wish Google's API docs said "iOS or Mac" for the API credential options.