6
votes

I cannot authorize Google OAuth on ios, safari always say

400 That's an error.

Invalid parameter value for redirect_uri: Missing scheme: com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8

enter image description here I have checked API Key, Client_ID, client_secret on Google Console page many times and also create url scheme in the xcode.

Here are my Swift code:

oauthswift = OAuth2Swift( consumerKey: "xxxxx-3lmlrubo9345ng4qhtf62ud1i02m6ta8.apps.googleusercontent.com", consumerSecret: "xxxtg6qslUOC2np1sBg0hnWgBcpZb4", authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth", responseType: "token" ) let handle = oauthswift.authorize( withCallbackURL: URL(string: "com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8")!, scope: "profile", state:"GOOGLE", success: { credential, response, parameters in print(credential.oauthToken) // Do your request }, failure: { error in print(error.localizedDescription) } )

Could you help me ?

4

4 Answers

3
votes

It is pretty simple fix for this issue: just set prefix before your schema.

Example: your schema parameter:

com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8

the identifier of your iOS application:

net.the-red-queen.www

so, value for your redirect URI parameter is:

net.the-red-queen.www:com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8
1
votes

I think the actual issue is that you didn't specify a full URI. (The schema doesn't have a colon and then a path.) Try making your redirect_uri look something like the following (properly encoded, of course):

com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8:/oauth
0
votes

You should probably recheck the Google Dev Console. Your clientID might be wrongly registered for Javascript Web Apps rather than Mobile Apps

0
votes

I'm writing an Android client, and this information helped, but wasn't quite what I needed. I found that I had to make the redirect uri a little differently.

Take the uri that you're using as a target on the phone (usually the package name, but it can be different if re-defined in the applicationId in the app's build.gradle file).

Append this at the end of the target: :/oauth2callback

So my package is com.fooboy.testapp3. Add the above bit and the redirect uri becomes:

com.foobly.testapp3:/oauth2callback.

There are a lot of other things that need to be just right (especially in the google api console), but this was the final trick for me.

Good luck (you'll need it)!