Last active
January 26, 2017 17:02
-
-
Save frausto/7939449 to your computer and use it in GitHub Desktop.
Linkedin Oauth: Exchanging JSAPI token for a REST token using Ruby/Rails and the linkedin gem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.getScript("https://platform.linkedin.com/in.js?async=true", -> | |
IN.init({ | |
api_key: <<API Key>>, | |
authorize: true, | |
credentials_cookie: true | |
}) | |
) | |
linkedinImport = -> | |
IN.User.authorize( -> | |
$.post('https://localhost:3000/oauth/linkedin') | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#initializer | |
ENV["LINKEDIN_APP_ID"] = #<<OAuth User Token>> | |
ENV['LINKEDIN_SECRET'] = #<<OAuth User Secret>> | |
ENV['LINKEDIN_API_KEY'] = #<<API Key>> | |
ENV['LINKEDIN_API_SECRET'] = #<<Secret Key>> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OauthController < Api::ApiController | |
def linkedin | |
linkedin_auth = JSON.parse(request.cookies["linkedin_oauth_#{ENV['LINKEDIN_API_KEY']}"]) | |
client = LinkedIn::Client.new(ENV["LINKEDIN_API_KEY"], ENV['LINKEDIN_API_SECRET']) | |
consumer = client.consumer | |
token = consumer.get_access_token(nil, {}, { | |
'xoauth_oauth2_access_token' => linkedin_auth['access_token'] | |
}) | |
client.authorize_from_access(token.token, token.secret) | |
profile_info = client.profile({ | |
:fields => ['id', 'first-name', 'last-name', 'picture-url', 'positions:(title,company:(name))'] | |
}) | |
#do whatever | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment