Oauth 2.0 Ruby wrapper for the LinkedIn API. Heavily inspired by pengwynn/linkedin's Oauth 1.0 Linkedin API interface. Most methods are the same as pengwynn/linkedin's gem, but major terminology changes make this incompatible.
[sudo] gem install linkedin-oauth2
LinkedIn's API uses OAuth 2.0 for authentication. Luckily, this gem hides most of the gory details from you.
The gory details can be found here
For legacy support of LinkedIn's OAuth 1.0a api, refer to the pengwynn/linkedin gem.
Basically, you need 3 things to start using LinkedIn's API:
- Your application's
client_id
aka API Key - Your application's
client_secret
aka Secret Key - An
access_token
from a user who authorized your app.
Then you have already authenticated! Encoded within that access token are all of the permissions you have on a given user. Assuming you requested the appropriate permissions, you can read their profile, grab connections, etc.
client = LinkedIn::Client.new("<your client_id>",
"<your client_secret>",
"<user access_token>")
client.profile
You may also use the set_access_token
method.
client.set_access_token("<user access_token>", options)
There are 4 steps:
-
Setup a client using your application's
client_id
andclient_secret
client = LinkedIn::Client.new('your_client_id', 'your_client_secret')
-
Get the
authorize_url
to bring up the page that will ask a user to verify permissions & grant you access.authorize_url = client.authorize_url
-
Once a user signs in to your OAuth 2.0 box, you will get an
auth_code
aka code. (Check in url you were directed to after a successful auth). Use this auth code to request the access token.access_token = client.request_access_token("<auth_code from last step>")
-
Once you have an
access_token
, you can request profile information or anything else you have permissions for.client.profile
# get the profile for the authenticated user
client.profile
# get a profile for someone found in network via ID
client.profile(:id => 'gNma67_AdI')
# get a profile for someone via their public profile url
client.profile(:url => 'http://www.linkedin.com/in/netherland')
More examples in the examples folder.
For a nice example on using this in a Rails App.
If you want to play with the LinkedIn api without using the gem, have a look at the apigee LinkedIn console.
- The term
consumer
is now referred to as theclient
- The terms
token
,consumer token
, orconsumer key
in OAuth 1.0 are now referred to asclient_id
in OAuth 2.0 - The terms
secret
, orconsumer secret
in OAuth 1.0 are now referred to asclient_secret
in OAuth 2.0 - In OAuth 1.0 there is both an
auth token
and anauth secret
. OAuth 2.0 combines these into a singleaccess token
. - The terms
auth token
,auth key
,auth secret
,access secret
,access token
, oraccess key
have all been collapsed and are now referred to as theaccess token
. require
linkedin-oauth2
instead oflinkedin
- Removed proxy options
- In general, any place that said "consumer" now says "client"
- The
authorize_from_request
method has been deprecated. Instead navigate to the url fromauthorize_url
then enter the returned code into therequest_access_token
method. - The
authorize_from_access
method has been deprecated. Instead initialize theLinkedIn::Client.new
with theaccess_token
.client = Linkedin::Client.new(client_id, client_secret, access_token)
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it. This is important so I don't break it in a future version unintentionally.
- Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
- Send me a pull request. Bonus points for topic branches.
Run bundle install
Copyright (c) 2013 Evan Morikawa. See LICENSE for details.