1

I am trying to enable server side offline access to Google APIs where the user authenticates from an iOS app. This is to allow a server to have continual access to Google APIs outside of the iOS app.

Google documents the approach below: https://developers.google.com/identity/sign-in/ios/offline-access

I've followed their documentation exactly with a barebones project. However, whenever I try to exchange the one-time authorization code for access and refresh tokens, I receive a 'redirect_uri_mismatch' error during the exchange.

I've searched forums and a number of folks recommended to configure the Google API project OAuth 2.0 client ID (from Google developer console) with no redirect URIs. However this causes the error 'Missing property "redirect_uris" in a client type of "web"'

I've also tried other OAuth 2.0 client ID types (e.g., Other) but with no luck.

Has anyone been able to get this flow to work? Any help would be greatly appreciated!

pat_cs
  • 19
  • 2

2 Answers2

0

I've bumped into this also. Google's example is wrong or at least incomplete. You have to set a redirect uri on the developer console and pass it to the oauth client like so:

credentials = client.credentials_from_clientsecrets_and_code(
CLIENT_SECRET_FILE,
['https://www.googleapis.com/auth/drive.appdata', 'profile', 'email'],
auth_code, None, "your redirect uri")

Full documentation here http://oauth2client.readthedocs.io/en/latest/source/oauth2client.client.html

  • it's been 3 years but still: what should "your redirect uri" actually be? Assuming it's running server-side (headless), no browser, the user already consented (that's how we got the server auth code in the first place), I don't want a redirect URI - I just want a valid & authorized Python client interface to keep issuing commands.. – Sagi Mann Mar 22 '20 at 14:38
0

Set redirect_uri to urn:ietf:wg:oauth:2.0:oob in your code, it is used for installed app. As mentioned by @oravecz over here. This worked for me.

Adit Srivastava
  • 95
  • 1
  • 3
  • 10