Thursday, 30 January 2014

Android Oauth2.0 Implict login

Let’s be honest, from a mobile point of view implementing OAuth is like going to the DMV because you moved or your driver’s license expired.
It sucks.
But you have to do it.
note: if your are still pure and naive and you don’t know OAuth yet, you can take a look at these slides.
Basically OAuth is a login protocol between a web application A and a web application B which uses the web application A API.
It is pretty well designed when it comes to implement it in a web app (some people don’t love it, though…). But it becomes a nightmare when your “web application B” is actually a mobile application!!
Anyways, that was my feelings before I came across this tutorial from Foursquare which presents a pretty straight forward approach to do it hijacking the Android webView.
The GitHub example
OAuth flow implementation can change from a service to another. For Foursquare it works “out of the box”. Let’s see what you have to change if you want to run it to connect with GitHub API.
Foursquare enables you to directly request for the access_token from with your client_id in GET request. With GitHub you will have to :
1. Ask for a the access_code from your client_id in a GET request,
2. Ask for the access_token from your client_id, client_secret and acess_code in a POST request.