omniauth-linkedin 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5739865a590da6b43a2061707ce034055d06d79e
4
+ data.tar.gz: b055f89bfcada21c4b11606f82082bab14518f05
5
+ SHA512:
6
+ metadata.gz: d665d65e7779fb016be9a770e7f31c121c6986d6f646dc3fafea70e113e529a59113d3d9a48a1574a79fde1feb93f34e1cb4f794287ad808e214f9ab51553479
7
+ data.tar.gz: f2140b74d209042b74c687f7f863ab84a9efbddcc31aa6e383430e6be5f1b6b2533afd14f3cabb17a55e5c88976216831d7f8925a4f236480f45cbd854bc1419
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
2
  --format=progress
3
+ --require spec_helper
@@ -0,0 +1,2 @@
1
+ 2.1.2
2
+
data/README.md CHANGED
@@ -8,14 +8,18 @@ LinkedIn uses the OAuth 1.0a flow, you can read about it here: https://developer
8
8
 
9
9
  Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile` along side omniauth:
10
10
 
11
- gem 'omniauth'
12
- gem 'omniauth-linkedin'
11
+ ```ruby
12
+ gem 'omniauth'
13
+ gem 'omniauth-linkedin'
14
+ ```
13
15
 
14
16
  Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
15
17
 
16
- Rails.application.config.middleware.use OmniAuth::Builder do
17
- provider :linkedin, "consumer_key", "consumer_secret"
18
- end
18
+ ```ruby
19
+ Rails.application.config.middleware.use OmniAuth::Builder do
20
+ provider :linkedin, "consumer_key", "consumer_secret"
21
+ end
22
+ ```
19
23
 
20
24
  You will obviously have to put in your key and secret, which you get when you register your app with LinkedIn (they call them API Key and Secret Key).
21
25
 
@@ -27,50 +31,120 @@ LinkedIn recently (August 2012) provided the ability to request different permis
27
31
 
28
32
  By default, omniauth-linkedin requests the following permissions:
29
33
 
30
- "r_basicprofile r_emailaddress"
34
+ ```ruby
35
+ "r_basicprofile r_emailaddress"
36
+ ```
31
37
 
32
38
  This allows us to obtain enough information from LinkedIn to satisfy the requirements for the basic auth hash schema.
33
39
 
34
40
  To change the scope, simply change your initializer to something like this:
35
41
 
36
- Rails.application.config.middleware.use OmniAuth::Builder do
37
- provider :linkedin, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network'
38
- end
42
+ ```ruby
43
+ Rails.application.config.middleware.use OmniAuth::Builder do
44
+ provider :linkedin, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network'
45
+ end
46
+ ```
39
47
 
40
48
  One thing to note is the fact that when you ask for extra permissions, you will probably want to specify the array of fields that you want returned in the omniauth hash. If you don't then only the default fields (see below) will be returned which would defeat the purpose of asking for the extra permissions. So do the following:
41
49
 
42
- Rails.application.config.middleware.use OmniAuth::Builder do
43
- provider :linkedin, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]
44
- end
50
+ ```ruby
51
+ Rails.application.config.middleware.use OmniAuth::Builder do
52
+ provider :linkedin, "consumer_key", "consumer_secret", :scope => 'r_fullprofile r_emailaddress r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]
53
+ end
54
+ ```
45
55
 
46
56
  We have to repeat the list of default fields in order to get the extra 'connections' field.
47
57
 
48
58
  The list of default fields is as follows:
49
59
 
50
- ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location"]
60
+ ```ruby
61
+ ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location"]
62
+ ```
51
63
 
52
64
  To see a complete list of available fields, consult the LinkedIn documentation at https://developer.linkedin.com/documents/profile-fields
53
65
 
66
+ ## Example Auth Hash
67
+
68
+ Here's an example *Auth Hash* available in `request.env['omniauth.auth']`:
69
+
70
+ ```ruby
71
+ {
72
+ "provider"=>"linkedin",
73
+ "uid"=>"AbC123",
74
+ "info"=> {
75
+ "name"=>"John Doe",
76
+ "email"=>"john@doe.com",
77
+ "nickname"=>"John Doe",
78
+ "first_name"=>"John",
79
+ "last_name"=>"Doe",
80
+ "location"=>"Greater Boston Area, US",
81
+ "description"=>"Senior Developer, Hammertech",
82
+ "image"=> "http://m.c.lnkd.licdn.com/mpr/mprx/0_aBcD...",
83
+ "phone"=>"null",
84
+ "headline"=> "Senior Developer, Hammertech",
85
+ "industry"=>"Internet",
86
+ "urls"=>{
87
+ "public_profile"=>"http://www.linkedin.com/in/johndoe"
88
+ }
89
+ },
90
+ "credentials"=> {
91
+ "token"=>"12312...",
92
+ "secret"=>"aBc..."
93
+ },
94
+ "extra"=>
95
+ {
96
+ "access_token"=> {
97
+ "token"=>"12312...",
98
+ "secret"=>"aBc...",
99
+ "consumer"=>nil, #<OAuth::Consumer>
100
+ "params"=> {
101
+ :oauth_token=>"12312...",
102
+ :oauth_token_secret=>"aBc...",
103
+ :oauth_expires_in=>"5183999",
104
+ :oauth_authorization_expires_in=>"5183999",
105
+ },
106
+ "response"=>nil #<Net::HTTPResponse>
107
+ },
108
+ "raw_info"=> {
109
+ "firstName"=>"Joe",
110
+ "headline"=>"Senior Developer, Hammertech",
111
+ "id"=>"AbC123",
112
+ "industry"=>"Internet",
113
+ "lastName"=>"Doe",
114
+ "location"=> {"country"=>{"code"=>"us"}, "name"=>"Greater Boston Area"},
115
+ "pictureUrl"=> "http://m.c.lnkd.licdn.com/mpr/mprx/0_aBcD...",
116
+ "publicProfileUrl"=>"http://www.linkedin.com/in/johndoe"
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
54
122
  ## Using It With The LinkedIn Gem
55
123
 
56
124
  You may find that you want to use OmniAuth for authentication, but you want to use an API wrapper such as this one https://github.com/pengwynn/linkedin to actually make your api calls. But the LinkedIn gem provides it's own way to authenticate with LinkedIn via OAuth. In this case you can do the following.
57
125
 
58
126
  Configure the LinkedIn gem with your consumer key and secret:
59
127
 
60
- LinkedIn.configure do |config|
61
- config.token = "consumer_key"
62
- config.secret = "consumer_secret"
63
- end
128
+ ```ruby
129
+ LinkedIn.configure do |config|
130
+ config.token = "consumer_key"
131
+ config.secret = "consumer_secret"
132
+ end
133
+ ```
64
134
 
65
- Use OmniAuth as per normal to obtain an access token and an access token secret for your user. Now create the LinkedIn client and authorize it using the access token and secret that you ontained via OmniAuth:
135
+ Use OmniAuth as per normal to obtain an access token and an access token secret for your user. Now create the LinkedIn client and authorize it using the access token and secret that you obtained via OmniAuth:
66
136
 
67
- client = LinkedIn::Client.new
68
- client.authorize_from_access("access_token", "access_token_secret")
137
+ ```ruby
138
+ client = LinkedIn::Client.new
139
+ client.authorize_from_access("access_token", "access_token_secret")
140
+ ```
69
141
 
70
142
  You can now make API calls as per normal e.g.:
71
143
 
72
- client.profile
73
- client.add_share({:comment => "blah"})
144
+ ```ruby
145
+ client.profile
146
+ client.add_share({:comment => "blah"})
147
+ ```
74
148
 
75
149
  ## Note on Patches/Pull Requests
76
150
 
@@ -2,7 +2,7 @@ require "omniauth-linkedin/version"
2
2
  require 'omniauth/strategies/linkedin'
3
3
 
4
4
 
5
- module Omniauth
5
+ module OmniAuth
6
6
  module Linkedin
7
7
  # Your code goes here...
8
8
  end
@@ -1,5 +1,5 @@
1
- module Omniauth
1
+ module OmniAuth
2
2
  module Linkedin
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -44,7 +44,9 @@ module OmniAuth
44
44
  end
45
45
 
46
46
  def raw_info
47
- @raw_info ||= MultiJson.decode(access_token.get("/v1/people/~:(#{options.fields.join(',')})?format=json").body)
47
+ fields = options.fields
48
+ fields.map! { |f| f == "picture-url" ? "picture-url;secure=true" : f } if options[:secure_image_url]
49
+ @raw_info ||= MultiJson.decode(access_token.get("/v1/people/~:(#{fields.join(',')})?format=json").body)
48
50
  end
49
51
 
50
52
  def request_phase
@@ -4,7 +4,7 @@ require "omniauth-linkedin/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "omniauth-linkedin"
7
- s.version = Omniauth::Linkedin::VERSION
7
+ s.version = OmniAuth::Linkedin::VERSION
8
8
  s.authors = ["Alan Skorkin"]
9
9
  s.email = ["alan@skorks.com"]
10
10
  s.homepage = "https://github.com/skorks/omniauth-linkedin"
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_runtime_dependency 'omniauth-oauth', '~> 1.0'
20
20
 
21
- s.add_development_dependency 'rspec', '~> 2.7'
21
+ s.add_development_dependency 'rspec', '~> 3.0'
22
22
  s.add_development_dependency 'rake'
23
23
  s.add_development_dependency 'webmock'
24
24
  s.add_development_dependency 'rack-test'
@@ -1,59 +1,57 @@
1
- require 'spec_helper'
2
-
3
- describe "OmniAuth::Strategies::LinkedIn" do
4
- subject do
1
+ RSpec.describe OmniAuth::Strategies::LinkedIn do
2
+ subject(:linkedin) do
5
3
  OmniAuth::Strategies::LinkedIn.new(nil, @options || {})
6
4
  end
7
5
 
8
- it 'should add a camelization for itself' do
9
- OmniAuth::Utils.camelize('linkedin').should == 'LinkedIn'
6
+ it 'adds a camelization for itself' do
7
+ expect(OmniAuth::Utils.camelize('linkedin')).to eq 'LinkedIn'
10
8
  end
11
9
 
12
10
  context 'client options' do
13
11
  it 'has correct LinkedIn site' do
14
- subject.options.client_options.site.should eq('https://api.linkedin.com')
12
+ expect(linkedin.options.client_options.site).to eq 'https://api.linkedin.com'
15
13
  end
16
14
 
17
15
  it 'has correct request token path' do
18
- subject.options.client_options.request_token_path.should eq('/uas/oauth/requestToken')
16
+ expect(linkedin.options.client_options.request_token_path).to eq '/uas/oauth/requestToken'
19
17
  end
20
18
 
21
19
  it 'has correct access token path' do
22
- subject.options.client_options.access_token_path.should eq('/uas/oauth/accessToken')
20
+ expect(linkedin.options.client_options.access_token_path).to eq '/uas/oauth/accessToken'
23
21
  end
24
22
 
25
23
  it 'has correct authorize url' do
26
- subject.options.client_options.authorize_url.should eq('https://www.linkedin.com/uas/oauth/authenticate')
24
+ expect(linkedin.options.client_options.authorize_url).to eq 'https://www.linkedin.com/uas/oauth/authenticate'
27
25
  end
28
26
  end
29
27
 
30
28
  context '#uid' do
31
- before :each do
32
- subject.stub(:raw_info) { { 'id' => '123' } }
29
+ before do
30
+ allow(linkedin).to receive(:raw_info).and_return('id' => '123')
33
31
  end
34
32
 
35
33
  it 'returns the id from raw_info' do
36
- subject.uid.should eq('123')
34
+ expect(linkedin.uid).to eq '123'
37
35
  end
38
36
  end
39
37
 
40
38
  context 'returns info hash conformant with omniauth auth hash schema' do
41
- before :each do
42
- subject.stub(:raw_info) { {} }
39
+ before do
40
+ allow(linkedin).to receive(:raw_info).and_return({})
43
41
  end
44
42
 
45
43
  context 'and therefore has all the necessary fields' do
46
- it {subject.info.should have_key :name}
47
- it {subject.info.should have_key :name}
48
- it {subject.info.should have_key :email}
49
- it {subject.info.should have_key :nickname}
50
- it {subject.info.should have_key :first_name}
51
- it {subject.info.should have_key :last_name}
52
- it {subject.info.should have_key :location}
53
- it {subject.info.should have_key :description}
54
- it {subject.info.should have_key :image}
55
- it {subject.info.should have_key :phone}
56
- it {subject.info.should have_key :urls}
44
+ it {expect(linkedin.info).to have_key :name}
45
+ it {expect(linkedin.info).to have_key :name}
46
+ it {expect(linkedin.info).to have_key :email}
47
+ it {expect(linkedin.info).to have_key :nickname}
48
+ it {expect(linkedin.info).to have_key :first_name}
49
+ it {expect(linkedin.info).to have_key :last_name}
50
+ it {expect(linkedin.info).to have_key :location}
51
+ it {expect(linkedin.info).to have_key :description}
52
+ it {expect(linkedin.info).to have_key :image}
53
+ it {expect(linkedin.info).to have_key :phone}
54
+ it {expect(linkedin.info).to have_key :urls}
57
55
  end
58
56
  end
59
57
  end
metadata CHANGED
@@ -1,94 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-linkedin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alan Skorkin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-10 00:00:00.000000000 Z
11
+ date: 2014-06-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: omniauth-oauth
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '2.7'
33
+ version: '3.0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '2.7'
40
+ version: '3.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: webmock
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rack-test
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  description: LinkedIn strategy for OmniAuth.
@@ -98,9 +87,9 @@ executables: []
98
87
  extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
- - .gitignore
102
- - .rspec
103
- - .rvmrc
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".ruby-version"
104
93
  - Gemfile
105
94
  - Guardfile
106
95
  - README.md
@@ -116,32 +105,27 @@ files:
116
105
  - todo.txt
117
106
  homepage: https://github.com/skorks/omniauth-linkedin
118
107
  licenses: []
108
+ metadata: {}
119
109
  post_install_message:
120
110
  rdoc_options: []
121
111
  require_paths:
122
112
  - lib
123
113
  required_ruby_version: !ruby/object:Gem::Requirement
124
- none: false
125
114
  requirements:
126
- - - ! '>='
115
+ - - ">="
127
116
  - !ruby/object:Gem::Version
128
117
  version: '0'
129
- segments:
130
- - 0
131
- hash: 2699125881048178184
132
118
  required_rubygems_version: !ruby/object:Gem::Requirement
133
- none: false
134
119
  requirements:
135
- - - ! '>='
120
+ - - ">="
136
121
  - !ruby/object:Gem::Version
137
122
  version: '0'
138
- segments:
139
- - 0
140
- hash: 2699125881048178184
141
123
  requirements: []
142
124
  rubyforge_project:
143
- rubygems_version: 1.8.24
125
+ rubygems_version: 2.2.2
144
126
  signing_key:
145
- specification_version: 3
127
+ specification_version: 4
146
128
  summary: LinkedIn strategy for OmniAuth.
147
- test_files: []
129
+ test_files:
130
+ - spec/omniauth/strategies/linkedin_spec.rb
131
+ - spec/spec_helper.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm --create 1.9.3@omniauth-linkedin