Android Oauth 2.0

Hi Guys. Now I am starting a new series with name of Social Networking. Basically in this series first I will talk to you about Oauth2.0 module in Android and after that I will try to make Social Network libs like Facebook, Google, Twitter, LinkedIn and many more using our Oauth2.0 Module. So are you ready …

OK. I am using Android Studio 1.0 for this series. In Oauth2.0 I did not tell you about Oauth2.0 instead I talk with you how we use this module in our applications.


In our mostly Android apps, we want to integrate Facebook, Google etc for sign-in or share purpose. For that we add Facebook SDK , Google play service for Google+ and we only want one functionality. Its mean we are adding a long list of methods in our app but we only want one method. Instead many developers face multidex issue due to increase in method limit. Also one more issue, first I need to learn how integrate Facebook then Google then Twitter and a long list. So I feel, I create a one generic module which we use for every Social network. So for that purpose I created a Oauth2.0 Module. So any Social Network who uses Oauth2.0 for authentication, you can use this module for that Social Network.

1. Download EasySocial Module from Github.

2. Create a new project in Android Studio.

Android Studio Project.

3. Import EasySocial Module in our project. Go to File -> Import Module.

Import Module

4. Now add android dependency. File -> Project Structure.

Add Dependency.

In above image click the plus button and add as Module dependence.

5. Now create a Simple new activity in our app.

Activity GUI.

6. Now here we need to take a decision about a Social Network. So I decided, we are using Facebook for this tutorial but you can use Google or LinkedIn or any other which use Oauth2.0. Now create an app on and select a Web as platform. Now I have all credential which i need for Facebook authentication. Now final part our activity code.

7. Our Activity.

Activity code.

I think above code is very simple. So going to next part.

Activity Code.

Here the above method call when user click a button. Very simple in every Oauth2.0 we need three things.

  1. Login Url
  2. Redirect Url
  3. Access Token Url

The above three Urls we get from our Social Network documentation.

Activity code.

So now when process complete if authentication successful. We will see access token on our screen and if some error occur we will see toast on screen. So now here we have a access token and as we know if we need to get user info, post message or any thing on Facebook we only need to append access token with the url. For example I want to get userInfo, for that I will send Get request on this url.

Screen shoots of App for motivation.

Screen Shoot

Screen Shoot

Screen Shoot


Screen Shoot

Final thing I am saying this is a generic Oauth2.0 module. For proof, I am commenting some code and setting LinkedIn Url’s and showing you same code work for LinkedIn authentication.

Commented Code.

Now after changing in the code. I got result showing below :).

Application GUI.

Application GUI.

Application GUI.


Access Token.


Complete code of testing app also available on Github.

Now I will try to launch next tutorials as early as possible in which we create a Facebook, Google+, LinkedIn and Twitter libs modules for Android in which we will use our Oauth2.0 module.


Facebooktwitterredditpinterestlinkedinmailby feather

1 thought on “Android Oauth 2.0

  1. I simply want to mention I am all new to blogging and site-building and definitely loved this web blog. Very likely I’m likely to bookmark your blog . You certainly have superb well written articles. Thanks a lot for revealing your blog site.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.