omniauth-linkedin-openid 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 200128bdbafbd862d10c5694e699ca036ad03a195b3f24ebd407747243470591
4
+ data.tar.gz: 24dd2b40e1e9ce855829c3ed5850b2f45e89348b583655c7895a90ce4252af7d
5
+ SHA512:
6
+ metadata.gz: 511d291fec173c1f43e5d2df576e7165228fedc46dbd6992a708c9b4f0e7eea81efadf4b46bba5e963623a6b8b7ebeacdd9ee7159cc3c1cf985de7438c8c9921
7
+ data.tar.gz: 96fc2818001fac2167e991c61d6753418e5ae8046c50211939d9c054cdf1804b42c77582217a0c84793e9f5d05025c4798c55a3410dedea7cad87f4cc8bfff23
@@ -0,0 +1,24 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: ['2.4', '2.5', '2.6', '2.7', '3.0', '3.1', '3.2', 'truffleruby-head']
15
+
16
+ steps:
17
+ - uses: actions/checkout@v3
18
+ - name: Set up Ruby ${{ matrix.ruby-version }}
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby-version }}
22
+ bundler-cache: true
23
+ - name: Build and test with Rake
24
+ run: bundle exec rake
data/.gitignore ADDED
@@ -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,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-github.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Jarrett Lusso
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # OmniAuth LinkedIn
2
+
3
+ ![Ruby](https://github.com/omniauth/omniauth-github/workflows/Ruby/badge.svg?branch=master)
4
+ [![Gem](https://img.shields.io/gem/v/omniauth-linkedin-openid)](https://rubygems.org/gems/omniauth-linkedin-openid)
5
+
6
+ This is the a OmniAuth strategy for authenticating to LinkedIn using OpenID. To
7
+ use it, you'll need to register an application on the
8
+ [LinkedIn Apps Page](https://www.linkedin.com/developers/apps) to get your
9
+ Client ID and Client Secret. Additionally, you'll need to request access to the
10
+ "Sign In with LinkedIn using OpenID Connect" product.
11
+
12
+ For more details, read the [Sign In with LinkedIn using OpenID Connect](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2) documentation.
13
+
14
+ ## Installation
15
+
16
+ ```ruby
17
+ gem 'omniauth-linkedin-openid'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ```ruby
23
+ use OmniAuth::Builder do
24
+ provider :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET']
25
+ end
26
+ ```
27
+
28
+ ## Authenticating Members
29
+
30
+ With the LinkedIn API, you have the ability to specify which permissions you want users to grant your application. For more details, read the LinkedIn [Authenticating Members](https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2#authenticating-members) documentation.
31
+
32
+ The following scopes are requested by default:
33
+
34
+ 'openid profile email'
35
+
36
+ Here is an example of how you can configure the `scope` option:
37
+
38
+ ```ruby
39
+ provider :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'],
40
+ scope: 'openid profile email'
41
+ ```
42
+
43
+ ## Profile Fields
44
+
45
+ When specifying which permissions you want users to grant to your application, you can also specify the array of fields that you want returned in the OmniAuth hash. The following fields are requested by default:
46
+
47
+ ```ruby
48
+ %w(id full-name first-name last-name picture-url email-address)
49
+ ```
50
+
51
+ Here is an example of how you can configure the `fields` option:
52
+
53
+ ```ruby
54
+ provider :linkedin, ENV['LINKEDIN_CLIENT_ID'], ENV['LINKEDIN_CLIENT_SECRET'],
55
+ fields: %w(id full-name email-address)
56
+ ```
57
+
58
+ To see a complete list of available fields, read the LinkedIn [Profile Fields](https://learn.microsoft.com/en-us/linkedin/shared/references/fields) documentation.
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jclusso/omniauth-linkedin-openid.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ desc 'Run specs'
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "omniauth-linkedin-openid"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,89 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class LinkedIn < OmniAuth::Strategies::OAuth2
6
+ option :name, 'linkedin'
7
+
8
+ option :client_options, {
9
+ :site => 'https://api.linkedin.com',
10
+ :authorize_url => 'https://www.linkedin.com/oauth/v2/authorization?response_type=code',
11
+ :token_url => 'https://www.linkedin.com/oauth/v2/accessToken'
12
+ }
13
+
14
+ option :scope, 'openid profile email'
15
+ option :fields, %w(
16
+ id full-name first-name last-name picture-url email-address
17
+ )
18
+ option :redirect_url
19
+
20
+ uid do
21
+ raw_info['sub']
22
+ end
23
+
24
+ info do
25
+ {
26
+ email: raw_info['email'],
27
+ first_name: raw_info['given_name'],
28
+ last_name: raw_info['family_name'],
29
+ picture_url: raw_info['picture']
30
+ }
31
+ end
32
+
33
+ extra do
34
+ { 'raw_info' => raw_info }
35
+ end
36
+
37
+ def callback_url
38
+ return options.redirect_url if options.redirect_url
39
+
40
+ full_host + script_name + callback_path
41
+ end
42
+
43
+ alias :oauth2_access_token :access_token
44
+
45
+ def access_token
46
+ ::OAuth2::AccessToken.new(client, oauth2_access_token.token, {
47
+ expires_in: oauth2_access_token.expires_in,
48
+ expires_at: oauth2_access_token.expires_at,
49
+ refresh_token: oauth2_access_token.refresh_token
50
+ })
51
+ end
52
+
53
+ def raw_info
54
+ @raw_info ||= access_token.get(profile_endpoint).parsed
55
+ end
56
+
57
+ private
58
+
59
+ def fields_mapping
60
+ # https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext#api-request-to-retreive-member-details
61
+ {
62
+ 'id' => 'sub',
63
+ 'full-name' => 'name',
64
+ 'first-name' => 'given_name',
65
+ 'last-name' => 'family_name',
66
+ 'picture-url' => 'picture'
67
+ }
68
+ end
69
+
70
+ def fields
71
+ options.fields.each.with_object([]) do |field, result|
72
+ result << fields_mapping[field] if fields_mapping.has_key? field
73
+ end
74
+ end
75
+
76
+ def profile_endpoint
77
+ '/v2/userinfo'
78
+ end
79
+
80
+ def token_params
81
+ super.tap do |params|
82
+ params.client_secret = options.client_secret
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ OmniAuth.config.add_camelization 'linkedin', 'LinkedIn'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module LinkedInOpenID
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "omniauth-linkedin-openid/version"
2
+ require 'omniauth/strategies/linkedin'
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-linkedin-openid/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = 'Jarrett Lusso'
6
+ gem.email = 'jclusso@gmail.com'
7
+ gem.description = 'OmniAuth strategy for LinkedIn using OpenID.'
8
+ gem.summary = 'OmniAuth strategy for LinkedIn using OpenID.'
9
+ gem.homepage = 'https://github.com/jclusso/omniauth-linkedin-openid'
10
+ gem.license = 'MIT'
11
+
12
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.name = 'omniauth-linkedin-openid'
16
+ gem.require_paths = ['lib']
17
+ gem.version = OmniAuth::LinkedInOpenID::VERSION
18
+
19
+ gem.metadata = {
20
+ "bug_tracker_uri" => "https://github.com/jclusso/omniauth-linkedin-openid/issues",
21
+ "documentation_uri" => "https://github.com/jclusso/omniauth-linkedin-openid/README.md",
22
+ "source_code_uri" => "https://github.com/jclusso/omniauth-linkedin-openid"
23
+ }
24
+
25
+ gem.add_dependency 'omniauth', '~> 2.0'
26
+ gem.add_dependency 'omniauth-oauth2', '~> 1.8'
27
+ gem.add_development_dependency 'rspec', '~> 3.5'
28
+ gem.add_development_dependency 'rack-test'
29
+ gem.add_development_dependency 'webmock'
30
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-linkedin-openid'
3
+
4
+ describe OmniAuth::Strategies::LinkedIn do
5
+ subject { OmniAuth::Strategies::LinkedIn.new(nil) }
6
+
7
+ it 'adds camelization for itself' do
8
+ expect(OmniAuth::Utils.camelize('linkedin')).to eq('LinkedIn')
9
+ end
10
+
11
+ describe '#client' do
12
+ it 'has correct LinkedIn site' do
13
+ expect(subject.client.site).to eq('https://api.linkedin.com')
14
+ end
15
+
16
+ it 'has correct `authorize_url`' do
17
+ expect(subject.client.options[:authorize_url]).to eq('https://www.linkedin.com/oauth/v2/authorization?response_type=code')
18
+ end
19
+
20
+ it 'has correct `token_url`' do
21
+ expect(subject.client.options[:token_url]).to eq('https://www.linkedin.com/oauth/v2/accessToken')
22
+ end
23
+ end
24
+
25
+ describe '#callback_path' do
26
+ it 'has the correct callback path' do
27
+ expect(subject.callback_path).to eq('/auth/linkedin/callback')
28
+ end
29
+ end
30
+
31
+ describe '#uid' do
32
+ before :each do
33
+ allow(subject).to receive(:raw_info) { Hash['sub' => 'uid'] }
34
+ end
35
+
36
+ it 'returns the id from raw_info' do
37
+ expect(subject.uid).to eq('uid')
38
+ end
39
+ end
40
+
41
+ describe '#info / #raw_info' do
42
+ let(:access_token) { instance_double OAuth2::AccessToken }
43
+
44
+ let(:parsed_response) { Hash[:foo => 'bar'] }
45
+
46
+ let(:profile_endpoint) { '/v2/userinfo' }
47
+ let(:profile_response) { instance_double OAuth2::Response, parsed: parsed_response }
48
+
49
+ before :each do
50
+ allow(subject).to receive(:access_token).and_return access_token
51
+
52
+ allow(access_token).to receive(:get)
53
+ .with(profile_endpoint)
54
+ .and_return(profile_response)
55
+ end
56
+
57
+ it 'returns parsed responses using access token' do
58
+ expect(subject.info).to have_key :email
59
+ expect(subject.info).to have_key :first_name
60
+ expect(subject.info).to have_key :last_name
61
+ expect(subject.info).to have_key :picture_url
62
+
63
+ expect(subject.raw_info).to eq({ :foo => 'bar' })
64
+ end
65
+ end
66
+
67
+ describe '#extra' do
68
+ let(:raw_info) { Hash[:foo => 'bar'] }
69
+
70
+ before :each do
71
+ allow(subject).to receive(:raw_info).and_return raw_info
72
+ end
73
+
74
+ specify { expect(subject.extra['raw_info']).to eq raw_info }
75
+ end
76
+
77
+ describe '#access_token' do
78
+ let(:expires_in) { 3600 }
79
+ let(:expires_at) { 946688400 }
80
+ let(:token) { 'token' }
81
+ let(:refresh_token) { 'refresh_token' }
82
+ let(:access_token) do
83
+ instance_double OAuth2::AccessToken, :expires_in => expires_in,
84
+ :expires_at => expires_at, :token => token, :refresh_token => refresh_token
85
+ end
86
+
87
+ before :each do
88
+ allow(subject).to receive(:oauth2_access_token).and_return access_token
89
+ end
90
+
91
+ specify { expect(subject.access_token.expires_in).to eq expires_in }
92
+ specify { expect(subject.access_token.expires_at).to eq expires_at }
93
+ end
94
+
95
+ describe '#authorize_params' do
96
+ describe 'scope' do
97
+ before :each do
98
+ allow(subject).to receive(:session).and_return({})
99
+ end
100
+
101
+ it 'sets default scope' do
102
+ expect(subject.authorize_params['scope']).to eq('openid profile email')
103
+ end
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,13 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'rspec'
4
+ require 'rack/test'
5
+ require 'webmock/rspec'
6
+ require 'omniauth'
7
+ require 'omniauth-linkedin-openid'
8
+
9
+ RSpec.configure do |config|
10
+ config.include WebMock::API
11
+ config.include Rack::Test::Methods
12
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
13
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-linkedin-openid
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jarrett Lusso
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: OmniAuth strategy for LinkedIn using OpenID.
84
+ email: jclusso@gmail.com
85
+ executables:
86
+ - console
87
+ - setup
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".github/workflows/ruby.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/omniauth-linkedin-openid.rb
101
+ - lib/omniauth-linkedin-openid/version.rb
102
+ - lib/omniauth/strategies/linkedin.rb
103
+ - omniauth-linkedin-openid.gemspec
104
+ - spec/omniauth/strategies/linkedin_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/jclusso/omniauth-linkedin-openid
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ bug_tracker_uri: https://github.com/jclusso/omniauth-linkedin-openid/issues
111
+ documentation_uri: https://github.com/jclusso/omniauth-linkedin-openid/README.md
112
+ source_code_uri: https://github.com/jclusso/omniauth-linkedin-openid
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.2.33
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: OmniAuth strategy for LinkedIn using OpenID.
132
+ test_files:
133
+ - spec/omniauth/strategies/linkedin_spec.rb
134
+ - spec/spec_helper.rb