Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

LinkedIn JS API token exchange to REST token using Spring Social for Linkedin

$
0
0
I'm trying to do the following:

Let the user authenticate and authorize through Linkedin using Linkedin JSAPI, then take the authentication details and send them to my server to get the user profile via server side communication.

I got the Linkedin button setup, got the authorization cookie all the way to my server (as described here), and was able to verify that the token is indeed signed correctly with my secret key.

Now I'm stuck at the point where I am supposed to take the token I got from JSAPI and exchange it for an access token.

This is the code I'm using, as mentioned it uses Spring Social for Linkedin, and it doesn't work as it throws a 401 Unauthorized response:

LinkedInConnectionFactory connectionFactory =
new LinkedInConnectionFactory(myLinkedinId, myLinkedinSecret);
OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
AuthorizedRequestToken art = new AuthorizedRequestToken(new OAuthToken(theTokenIGotFromJSAPI, myLinkedinSecret), howDoICalculateThisSignature);
OAuthToken accessGrant = oauthOperations.exchangeForAccessToken(art, null);
if (accessGrant == null) return null;
Connection<LinkedIn> connection = connectionFactory.createConnection(accessGrant);
if (connection != null) {
LinkedIn linkedin = connection.getApi();
return linkedin.profileOperations().getUserProfile();
}

What I'm actually confused about is the AuthorizedRequestToken object. The theTokenIGotFromJSAPI part is simple enough I think, it's just access_token from JSAPI, but what about myLinkedinSecret, is it just my linkedin secret key? what about howDoICalculateThisSignature, how do I create that one? Do I use the same hash method as I used to validate the linkedin response and hash the access_token with my secret linkedin key?

In the linkedin page, it says:

You need to pass four values as query parameters:

  1. oauth_consumer_key, to identify yourself
  2. xoauth_oauth2_access_token parameter, set to the value of the access_token field in the cookie.
  3. signature_method set to HMAC-SHA1
  4. signature, calculated as described in the OAuth 1.0a spec

So (1) is automatically done by the connection I suppose, (2) is the access token I provided, but how do I do (3) and (4)?

Is there a better way to do this?

I'm using Spring Social v1.0.2.RELEASE, and social-Linkedin v1.0.0.RC1
I can upgrade or change versions as needed.

Viewing all articles
Browse latest Browse all 145

Trending Articles