I'm trying to set up Google OAuth with my iOS app and Rails web app. I have 2 separate clients (with of course different client IDs, but with the same prefix) set up in the API Console. One for the iOS app, and the other for the web app (which also has a client_secret
. I want to use the AppAuth SDK on iOS to get the user's auth code, then send that to my web app, which will then perform the exchange for the access token.
First of all, does this sound like a reasonable thing to do, or is it not possible to split the transaction across clients like that?
My first try was to just take the auth code and perform the exchange, but that failed with the missing_code_verifier
invalid_grant
error, so I also passed the same code_verifier
that AppAuth used to get the auth code to my server, and that fixed that error. First of all, is it necessary to pass this code verifier to the server? Seems a little strange.
Now though, it fails with the unauthorized_client
error. My web app is making a request like this:
{
"grant_type"=>"authorization_code",
"code"=>"4/XYZ...",
"client_id"=>"WEB_APP_CLIENT_ID_HERE.apps.googleusercontent.com",
"client_secret"=>"WEB_APP_CLIENT_SECRET_HERE",
"redirect_uri"=>"https://www.myapp.com/oauth_callback",
"parse"=>"json",
"code_verifier"=>"CODE_VERIFIER_STRING_HERE"
}
Looking at posts like:
- Unable to exchange authorization code for access token and refresh token in Cross Client google oauth2.0
- Google+ Sign-in for server-side apps, exchanging auth code for access token
it looks like the redirect_uri
might be an issue here. My AppAuth config on iOS has the redirect URI set as com.googleusercontent.apps.iOS_CLIENT_ID_HERE
, and the Info.plist
URL scheme too. The web app's "Authorized redirect URIs" section in the API Console has a bunch of web URLs, and I added the com.google...
to it as well. Is this config incorrect? Is the redirect_uri
important when doing cross-client auth?
Any help is greatly appreciated! All my trial-and-error have had no fruition so far :(