6

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 Answers 4

3

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
Sign up to request clarification or add additional context in comments.

1 Comment

I wonder whether Google changed the scheme format later on, because some tutorials do not mention this. This worked great, thanks a lot!
1

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

Comments

0

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

4 Comments

I checked again and also deleted the auto generated key for Web It still does not work
I changed withCallbackURL: URL(string: localhost them it allow to login google but cannot reopen the ios app
Did you add GoogleService-Info.plist to your app and a URL Type with REVERSED_CLIENT_ID to your app plist? Make sure your reversed Id matches with your iOS client Id on your Google Dev Console
absolutely yes anw, I have changed the scheme to com.googleusercontent.apps.984813079630-3lmlrubo9345ng4qhtf62ud1i02m6ta8:/oauth then it work now but another problem happens : stackoverflow.com/questions/44558561/…
0

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)!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.