Skip to content

Instantly share code, notes, and snippets.

@xs
Last active January 2, 2016 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xs/8360619 to your computer and use it in GitHub Desktop.
Save xs/8360619 to your computer and use it in GitHub Desktop.
JSAPI Token for REST API Oauth Token -> token_rejected error
get '/ajax/linkedin_auth' do
cookie = JSON.parse(request.cookies["linkedin_oauth_#{API_KEY}"])
verify_linkedin_cookie(cookie)
consumer = OAuth::Consumer.new(
API_KEY,
SECRET_KEY,
{
: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",
}
)
begin
request_token = consumer.get_request_token
access_token = request_token.get_access_token({}, {:xoauth_oauth2_access_token => cookie[:access_token]})
rescue => e
log.info(e)
binding.debug!
end
binding.debug!
end
def verify_linkedin_cookie(cookie)
base = cookie["signature_order"].map { |field| cookie[field] }.join
key = SECRET_KEY
signature = Base64.encode64(OpenSSL::HMAC.digest('sha1', key, base)).chomp
assert(signature == cookie["signature"], "The cookie we received from LinkedIn has an invalid signature - it may have been spoofed, or our LinkedIn secret key may have changed. The cookie in question: #{cookie}")
end
@xs
Copy link
Author

xs commented Jan 10, 2014

The error occurs in line 17 and is an instance of #<OAuth::Problem: token_rejected>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment