1
votes

I'm trying to exchange an Oauth2 token from the Linkedin JSAPI for an Oauth1 token and secret. As per the docs here.

I've made the request with the js library, logged in and receive the cookie with the Oauth2 token and signature.

{
    "signature_version": "1",
    "signature_method": "HMAC-SHA1",
    "signature_order": [
        "access_token",
        "member_id"
    ],
    "access_token": "j06JXCy1EB8plWmayCdUajMB6",
    "signature": "i0HmB5LQPf8NOz",
    "member_id": "hU7xxxxx"
}

Now I'm trying to exchange the access token for an Oauth1 token server side.

According to the docs, I can post the params to:

'https://api.linkedin.com/uas/oauth/accessToken'

Including the following params:

oauth_consumer_key
xoauth_oauth2_access_token parameter
signature_method
signature

I've done this with curl and get a message saying the signature is invalid. Which it's not, I've checked as per the instructions.

So, I've been trying with the oauth gem:

  consumer = OAuth::Consumer.new(
    key,
    consumer_secret,
    {
      :site => "https://api.linkedin.com",
      :http_method => :post,
      :request_token_path => "/uas/oauth/requestToken",
      :access_token_path => "/uas/oauth/accessToken",
      :authorize_path => "/uas/oauth/authorize",
    }
  )

request_token = consumer.get_request_token
access_token = request_token.get_access_token({}, {:xoauth_oauth2_access_token => token})

And again, that gives me the damn signature invalid error!

How on earth are you supposed to exchange these tokens? I've found limited advice online for the Ruby gem.

1

1 Answers

0
votes

I do this

consumer = OAuth::Consumer.new("[API KEY]", "[SECRET KEY]", {
    :site => "https://api.linkedin.com", 
    :authorize_path => "/uas/oauth/authorize", 
    :request_token_path => "/uas/oauth/requestToken", 
    :access_token_path => "/uas/oauth/accessToken"
})

Then:

client = OAuth::AccessToken.new(consumer, "[OAUTH USER TOKEN]", "[OAUTH USER SECRET]")

Then you make API calls like this:

response = JSON.parse(client.get(url, "x-li-format" => "json").body)

Let me know if it helps you.