Search code examples
iosgoogle-apioauth-2.0google-oauth

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?


Solution

  • 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.