How to use custom URI schemes in the redirect URI for native clients in Google OAuth FlowsHere
is a technique to improve the flow when an iOS app wants to get an
OAuth 2 token for a google account. You send the user to the browser
for approval, and the browser redirects back to a URI you supply. The
trick is to register and use a custom URI scheme for that redirect.
As an example, for the following bundle and client id:
bundle id: com.example.myapp
client id:
1234-abc.apps.googleusercontent.com
The client can use either of the following custom schemes:
com.example.myapp:/oauth2Callback com.googleusercontent.apps.1234-abc:/oauth2callbackTo use custom URI schemes:
Create
a client id of type iOS (installed application) in the API console.
Enter Bundle ID (Wildcards are supported e.g. com.mycompany.app1.*).
In
your app register your custom URI scheme and handle the request.
Extract the code and exchange it for a refresh token and store it.
More details:
http://goo.gl/uax5iG+ post:
https://plus.google.com/111487187212167051233/posts/AztHNnQh7w6