omniauth-linkedin-oauth2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-linkedin-oauth2.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # OmniAuth LinkedIn OAuth2 Strategy
2
+
3
+ A LinkedIn OAuth2 strategy for OmniAuth.
4
+
5
+ For more details, read the LinkedIn documentation: https://developer.linkedin.com/documents/authentication
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'omniauth-linkedin-oauth2'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install omniauth-linkedin-oauth2
20
+
21
+ ## Usage
22
+
23
+ Register your application with LinkedIn to receive an API key: https://www.linkedin.com/secure/developer
24
+
25
+ This is an example that you might put into a Rails initializer at `config/initializers/omniauth.rb`:
26
+
27
+ ```ruby
28
+ Rails.application.config.middleware.use OmniAuth::Builder do
29
+ provider :linkedin_oauth2, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']
30
+ end
31
+ ```
32
+
33
+ You can now access the OmniAuth LinkedIn OAuth2 URL: `/auth/linkedin_oauth2`.
34
+
35
+ ## Granting Member Permissions to Your Application
36
+
37
+ With the LinkedIn API, you have the ability to specify which permissions you want users to grant your application.
38
+ For more details, read the LinkedIn documentation: https://developer.linkedin.com/documents/authentication
39
+
40
+ By default, omniauth-linkedin-oauth2 requests the following permissions:
41
+
42
+ 'r_basicprofile r_emailaddress'
43
+
44
+ You can configure the scope option:
45
+
46
+ ```ruby
47
+ provider :linkedin_oauth2, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'], :scope => 'r_fullprofile r_emailaddress r_network'
48
+ ```
49
+
50
+ ## Profile Fields
51
+
52
+ When specifying which permissions you want to users to grant to your application, you will probably want to specify the array of fields that you want returned in the omniauth hash. The list of default fields is as follows:
53
+
54
+ ```ruby
55
+ ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url']
56
+ ```
57
+
58
+ Here's an example of a possible configuration where the the fields returned from the API are: id, email-address, first-name and last-name.
59
+
60
+ ```ruby
61
+ provider :linkedin_oauth2, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET'], :fields => ['id', 'email-address', 'first-name', 'last-name']
62
+ ```
63
+
64
+ To see a complete list of available fields, consult the LinkedIn documentation at: https://developer.linkedin.com/documents/profile-fields
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sinatra'
4
+ gem 'omniauth-linkedin-oauth2'
@@ -0,0 +1,31 @@
1
+ # Sample app for LinkedIn OAuth2 Strategy
2
+ # Make sure to setup the ENV variables LINKEDIN_KEY and LINKEDIN_SECRET
3
+ # Run with "bundle exec rackup"
4
+
5
+ require 'bundler/setup'
6
+ require 'sinatra/base'
7
+ require 'omniauth-linkedin-oauth2'
8
+
9
+ class App < Sinatra::Base
10
+ get '/' do
11
+ redirect '/auth/linkedin_oauth2'
12
+ end
13
+
14
+ get '/auth/:provider/callback' do
15
+ content_type 'application/json'
16
+ MultiJson.encode(request.env['omniauth.auth'])
17
+ end
18
+
19
+ get '/auth/failure' do
20
+ content_type 'application/json'
21
+ MultiJson.encode(request.env)
22
+ end
23
+ end
24
+
25
+ use Rack::Session::Cookie, :secret => 'change_me'
26
+
27
+ use OmniAuth::Builder do
28
+ provider :linkedin_oauth2, ENV['LINKEDIN_KEY'], ENV['LINKEDIN_SECRET']
29
+ end
30
+
31
+ run App.new
@@ -0,0 +1,2 @@
1
+ require "omniauth-linkedin-oauth2/version"
2
+ require "omniauth/strategies/linkedin_oauth2"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module LinkedInOAuth2
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,68 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class LinkedInOAuth2 < OmniAuth::Strategies::OAuth2
6
+ # Give your strategy a name.
7
+ option :name, 'linkedin_oauth2'
8
+
9
+ # This is where you pass the options you would pass when
10
+ # initializing your consumer from the OAuth gem.
11
+ option :client_options, {
12
+ :site => 'https://www.linkedin.com',
13
+ :authorize_url => '/uas/oauth2/authorization?response_type=code',
14
+ :token_url => '/uas/oauth2/accessToken'
15
+ }
16
+
17
+ option :scope, 'r_basicprofile r_emailaddress'
18
+ option :fields, ['id', 'email-address', 'first-name', 'last-name', 'headline', 'location', 'industry', 'picture-url', 'public-profile-url']
19
+
20
+ # These are called after authentication has succeeded. If
21
+ # possible, you should try to set the UID without making
22
+ # additional calls (if the user id is returned with the token
23
+ # or as a URI parameter). This may not be possible with all
24
+ # providers.
25
+ uid { raw_info['id'] }
26
+
27
+ info do
28
+ {
29
+ :name => user_name,
30
+ :email => raw_info['emailAddress'],
31
+ :nickname => user_name,
32
+ :first_name => raw_info['firstName'],
33
+ :last_name => raw_info['lastName'],
34
+ :location => raw_info['location'],
35
+ :description => raw_info['headline'],
36
+ :image => raw_info['pictureUrl'],
37
+ :urls => {
38
+ 'public_profile' => raw_info['publicProfileUrl']
39
+ }
40
+ }
41
+ end
42
+
43
+ extra do
44
+ { 'raw_info' => raw_info }
45
+ end
46
+
47
+ def access_token
48
+ ::OAuth2::AccessToken.new(client, super.token, {
49
+ :mode => :query,
50
+ :param_name => 'oauth2_access_token'
51
+ })
52
+ end
53
+
54
+ def raw_info
55
+ @raw_info ||= access_token.get("/v1/people/~:(#{options.fields.join(',')})?format=json").parsed
56
+ end
57
+
58
+ private
59
+
60
+ def user_name
61
+ name = "#{raw_info['firstName']} #{raw_info['lastName']}".strip
62
+ name.empty? ? nil : name
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ OmniAuth.config.add_camelization 'linkedin_oauth2', 'LinkedInOAuth2'
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-linkedin-oauth2/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-linkedin-oauth2"
8
+ gem.version = OmniAuth::LinkedInOAuth2::VERSION
9
+ gem.authors = ["Décio Ferreira"]
10
+ gem.email = ["decio.ferreira@decioferreira.com"]
11
+ gem.description = %q{A LinkedIn OAuth2 strategy for OmniAuth.}
12
+ gem.summary = %q{A LinkedIn OAuth2 strategy for OmniAuth.}
13
+ gem.homepage = "https://github.com/decioferreira/omniauth-linkedin-oauth2"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'omniauth', '~> 1.0'
21
+ gem.add_runtime_dependency 'omniauth-oauth2'
22
+
23
+ gem.add_development_dependency 'rspec', '~> 2.13.0'
24
+ gem.add_development_dependency 'simplecov'
25
+ end
@@ -0,0 +1,89 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-linkedin-oauth2'
3
+
4
+ describe OmniAuth::Strategies::LinkedInOAuth2 do
5
+ subject { OmniAuth::Strategies::LinkedInOAuth2.new(nil) }
6
+
7
+ it 'should add a camelization for itself' do
8
+ OmniAuth::Utils.camelize('linkedin_oauth2').should == 'LinkedInOAuth2'
9
+ end
10
+
11
+ describe '#client' do
12
+ it 'has correct LinkedIn site' do
13
+ subject.client.site.should eq('https://www.linkedin.com')
14
+ end
15
+
16
+ it 'has correct authorize url' do
17
+ subject.client.options[:authorize_url].should eq('/uas/oauth2/authorization?response_type=code')
18
+ end
19
+
20
+ it 'has correct token url' do
21
+ subject.client.options[:token_url].should eq('/uas/oauth2/accessToken')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'has the correct callback path' do
27
+ subject.callback_path.should eq('/auth/linkedin_oauth2/callback')
28
+ end
29
+ end
30
+
31
+ describe '#uid' do
32
+ before :each do
33
+ subject.stub(:raw_info) { { 'id' => 'uid' } }
34
+ end
35
+
36
+ it 'returns the id from raw_info' do
37
+ subject.uid.should eq('uid')
38
+ end
39
+ end
40
+
41
+ describe '#info' do
42
+ before :each do
43
+ subject.stub(:raw_info) { {} }
44
+ end
45
+
46
+ context 'and therefore has all the necessary fields' do
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 :urls }
56
+ end
57
+ end
58
+
59
+ describe '#extra' do
60
+ before :each do
61
+ subject.stub(:raw_info) { { :foo => 'bar' } }
62
+ end
63
+
64
+ it { subject.extra['raw_info'].should eq({ :foo => 'bar' }) }
65
+ end
66
+
67
+ describe '#raw_info' do
68
+ before :each do
69
+ response = double('response', :parsed => { :foo => 'bar' })
70
+ subject.stub(:access_token) { double('access token', :get => response) }
71
+ end
72
+
73
+ it 'returns parsed response from access token' do
74
+ subject.raw_info.should eq({ :foo => 'bar' })
75
+ end
76
+ end
77
+
78
+ describe '#authorize_params' do
79
+ describe 'scope' do
80
+ before :each do
81
+ subject.stub(:session => {})
82
+ end
83
+
84
+ it 'sets default scope' do
85
+ subject.authorize_params['scope'].should eq('r_basicprofile r_emailaddress')
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,20 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # Require this file using `require "spec_helper"` to ensure that it is only
7
+ # loaded once.
8
+ #
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-linkedin-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Décio Ferreira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-oauth2
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.13.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: A LinkedIn OAuth2 strategy for OmniAuth.
79
+ email:
80
+ - decio.ferreira@decioferreira.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - example/Gemfile
92
+ - example/config.ru
93
+ - lib/omniauth-linkedin-oauth2.rb
94
+ - lib/omniauth-linkedin-oauth2/version.rb
95
+ - lib/omniauth/strategies/linkedin_oauth2.rb
96
+ - omniauth-linkedin-oauth2.gemspec
97
+ - spec/omniauth/strategies/linkedin_oauth2_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: https://github.com/decioferreira/omniauth-linkedin-oauth2
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.24
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: A LinkedIn OAuth2 strategy for OmniAuth.
123
+ test_files:
124
+ - spec/omniauth/strategies/linkedin_oauth2_spec.rb
125
+ - spec/spec_helper.rb