Skip to content

Create Own Social Network Provider

vineetmobile edited this page Sep 23, 2013 · 5 revisions

This articles describes how you can create your own social network provider. In SocialAuth Android 3.0 we have introduced GenericProvider that can help you to achieve this task.This document assumes user is familiar with OAuth mechanism and creation of apps on social networks like facebook. Here we are looking to create Linkedin oAuth2 provider

Using OAuthConsumer.properties

You first need to do following steps :

  • See the provider that you are looking to create supports OAuth2 or OAuth1.
  • Note down Authorization URL, Request URL(for oAUTH1 only), Access Token URL , Any custom permissions require to access data(optional,some social client define it as scope also ex : full_profile for linkedin). You can get it from the documentation on developer website of provider.
  • Create consumer key and consumer secret. You can do this by creating an account on provider website and create your app. After creating the app you can obtain key , secret and callback url.
  • Now , if you need to specify the provider. The syntax is
socialauth. + providername   =   Generic Provider class 
Example  
For OAuth2 
socialauth.linkedin2  = org.brickred.socialauth.provider.GenericOAuth2Provider
For OAuth1 
socialauth.linkedin2  = org.brickred.socialauth.provider.GenericOAuth1Provider

socialauth already contains linkedin 1.0 provider , so try to use different name for your provider in case provider with same name already exist. GenericOAuth2Provider class handles all the oAuth mechanism for you. Available in socialauth java lib.

So this is how your oAuthconsumers.properties should look:

socialauth.linkedin2 = org.brickred.socialauth.provider.GenericOAuth2Provider
linkedin2.consumer_key = bh82t52rdos6
linkedin2.consumer_secret = zQ1LLrGbhDZ36fH8
linkedin2.custom_permissions = r_fullprofile
linkedin2.authentication_url = https://www.linkedin.com/uas/oauth2/authorization
linkedin2.access_token_url = https://www.linkedin.com/uas/oauth2/accessToken 
  • Now write following code (ShareBar Example)
// Add Bar to library
adapter = new SocialAuthAdapter(new ResponseListener());
// Use provider name as Generic, give same name to drawable
adapter.addProvider(Provider.GENERIC, R.drawable.linkedin);
// provide callback url name
adapter.addCallBack(Provider.GENERIC, "http://socialauth.in/socialauthdemo/socialAuthSuccessAction.do");
adapter.enable(bar);

Now your provider is added and it should do the authentication for you. After getting access token in response listener you need to use api method to make custom call like getting profile etc.

You may face number of issues before authentication which you may need to handle by modifying source code of socialauth android. Please mail us or post on issue thread for help.

Clone this wiki locally