Patrick Jackson
Patrick Jackson

Reputation: 19436

Google Oauth redirect to ios custom url

Goal: Complete Oauth2 from google in an iOS application.

I am using phonegap so I am launching the oauth in the browser. I want the redirect to be a custom url for my app so I can store the token. I have read this post on how to handle redirect but am still confused. What is the custom url that I should enter in my info.plist? What redirect to I pass to the oauth page?

var redirect_url='com.example.myapp:/oauth2Callback'
var url="https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=" + client_id + "&state=" + state + "&redirect_uri="+redirect_url+"&scope=" + scope;

Anyone experienced with this?

Upvotes: 4

Views: 5992

Answers (2)

Patrick Jackson
Patrick Jackson

Reputation: 19436

Turns out the above code is correct. My issue was with setting the custom url scheme in my info.plist. The url scheme needs to be the bundle id only(i.e. com.example.myexample). I had the ':/oauth2callback' appended to the end of it, which is incorrect.

Upvotes: 5

mariuss
mariuss

Reputation: 932

You can use either the iOS bundle id or the Google issued client id to form the custom scheme based redirect URI. The post you link to gives a couple of examples.

Do you have an Apple issued bundle id for your app? If not, did you register with the Google developer console (that gives you a client id)?

Upvotes: 1

Related Questions