omniauth-paypal-oauth2 1.4.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
+ SHA1:
3
+ metadata.gz: e858f9b31dcbdb2a17016d12f17b4bf8acac5105
4
+ data.tar.gz: fb46dfdb22debb4a9e814be9706ae801c74cb4ba
5
+ SHA512:
6
+ metadata.gz: a26124a6a3f214042b767df8cd650465f416d60769a59207c6cd0671f92d852c03d3349285ef5e7698735bdeece9c5ea9976f9f50b216b151cb98b731346e06e
7
+ data.tar.gz: 1f3dad26a5adc22edbc35e4a84650c4780a7674d3330cb0dd708f8e16852e57bc06e68164227078f3900fee8b00eb71fb3a42b9573174cd264f419bd5987b353
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'omniauth-oauth2', "~> 1.4.0"
6
+ gem 'json'
data/Gemfile.lock ADDED
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-paypal-oauth2 (1.3)
5
+ omniauth-oauth2 (~> 1.4.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ faraday (0.10.1)
12
+ multipart-post (>= 1.2, < 3)
13
+ hashie (3.4.6)
14
+ json (2.0.3)
15
+ jwt (1.5.6)
16
+ multi_json (1.12.1)
17
+ multi_xml (0.6.0)
18
+ multipart-post (2.0.0)
19
+ oauth2 (1.3.0)
20
+ faraday (>= 0.8, < 0.11)
21
+ jwt (~> 1.0)
22
+ multi_json (~> 1.3)
23
+ multi_xml (~> 0.5)
24
+ rack (>= 1.2, < 3)
25
+ omniauth (1.3.1)
26
+ hashie (>= 1.2, < 4)
27
+ rack (>= 1.0, < 3)
28
+ omniauth-oauth2 (1.4.0)
29
+ oauth2 (~> 1.0)
30
+ omniauth (~> 1.2)
31
+ rack (2.0.1)
32
+ rake (12.0.0)
33
+ rspec (2.99.0)
34
+ rspec-core (~> 2.99.0)
35
+ rspec-expectations (~> 2.99.0)
36
+ rspec-mocks (~> 2.99.0)
37
+ rspec-core (2.99.2)
38
+ rspec-expectations (2.99.2)
39
+ diff-lcs (>= 1.1.3, < 2.0)
40
+ rspec-mocks (2.99.4)
41
+
42
+ PLATFORMS
43
+ ruby
44
+ x86-mingw32
45
+
46
+ DEPENDENCIES
47
+ json
48
+ omniauth-oauth2 (~> 1.4.0)
49
+ omniauth-paypal-oauth2!
50
+ rake
51
+ rspec (~> 2.14)
52
+
53
+ BUNDLED WITH
54
+ 1.11.2
data/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # OmniAuth PayPal
2
+
3
+ **Note:** This gem is designed to work with OmniAuth 1.0 library.
4
+
5
+ This gem contains the Log In With PayPal strategy for OmniAuth.
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem "omniauth-paypal"
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`.
20
+
21
+ ```ruby
22
+ Rails.application.config.middleware.use OmniAuth::Builder do
23
+ provider :paypal, ENV['APP_ID'], ENV['APP_TOKEN'], sandbox: true, scope: "openid profile email"
24
+ end
25
+ ```
26
+
27
+ ## Attributes and Scopes
28
+
29
+ Log In With PayPal information can be found on https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/
30
+
31
+ The possible attributes to be returned at the moment are:
32
+
33
+ ```ruby
34
+ info['name']
35
+ info['email']
36
+ info['first_name'] # also available as given_name
37
+ info['last_name'] # also available as family_name
38
+ info['location']
39
+ info['name']
40
+ info['phone']
41
+
42
+ extra['account_creation_date']
43
+ extra['account_type']
44
+ extra['address']['country']
45
+ extra['address']['locality']
46
+ extra['address']['postal_code']
47
+ extra['address']['region']
48
+ extra['address']['street_address']
49
+ extra['language']
50
+ extra['locale']
51
+ extra['verified_account']
52
+ extra['zoneinfo']
53
+ extra['age_range']
54
+ extra['birthday']
55
+ ```
56
+
57
+ The actual set of attributes returned depends on the scopes set. The currently available scopes are:
58
+
59
+ ```
60
+ openid
61
+ profile
62
+ email
63
+ address
64
+ phone
65
+ https://uri.paypal.com/services/paypalattributes
66
+ https://uri.paypal.com/services/expresscheckout
67
+ ```
68
+
69
+ (those last 2 are scope names, not links)
70
+
71
+ For more details see the PayPal [list of attributes](https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#attributes).
72
+
73
+ ## Registering for an API key
74
+
75
+ To register your application for Log In With PayPal head over to the [PayPal Developer portal](https://developer.paypal.com/), log in and register for an application. Make sure to match your scope when registering your app to the scope provided when initializing Omniauth.
76
+
77
+ [A full tutorial is available](http://cristianobetta.com/blog/2013/09/27/integrating-login-with-paypal-into-rails/) on how to use Omniauth, Login With PayPal, and the PayPal Developer portal.
78
+
79
+ ## Example of result auth hash
80
+ With all scopes requested.
81
+
82
+ ```yaml
83
+ provider: paypal
84
+ uid: bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
85
+ info:
86
+ name: John Smith
87
+ email: example@example.com
88
+ first_name: John
89
+ last_name: Smith
90
+ given_name: John
91
+ family_name: Smith
92
+ location: Moscow
93
+ name: John Smith
94
+ phone: "71234567890"
95
+ credentials:
96
+ token: <token>
97
+ refresh_token: <refresh token>
98
+ expires_at: 1355082790
99
+ expires: true
100
+ extra:
101
+ account_creation_date: "2008-04-21"
102
+ account_type: PERSONAL
103
+ user_id: https://www.paypal.com/webapps/auth/identity/user/bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
104
+ address:
105
+ country: US
106
+ locality: San Jose
107
+ postal_code: "95131"
108
+ region: CA
109
+ street_address: 1 Main St
110
+ language: en_US
111
+ locale: en_US
112
+ verified_account: true
113
+ zoneinfo: America/Los_Angeles
114
+ age_range: 31-35
115
+ birthday: "1982-01-01"
116
+ ```
117
+
118
+ ## Contributing
119
+
120
+ Log In With PayPal has been in flux since I started this project and anything that helps keep this gem up to date and tested is greatly apprecitated. Thanks for your help!
121
+
122
+ ## License
123
+
124
+ Copyright (c) 2011 by veloGraf Systems
125
+
126
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
127
+
128
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
129
+
130
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -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 @@
1
+ require 'omniauth/paypal'
@@ -0,0 +1,2 @@
1
+ require 'omniauth/paypal/version'
2
+ require 'omniauth/strategies/paypal'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module PayPal
3
+ VERSION = "1.3"
4
+ end
5
+ end
@@ -0,0 +1,90 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class PayPal < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = "openid profile"
7
+ DEFAULT_RESPONSE_TYPE = "code"
8
+ SANDBOX_SITE = "https://api.sandbox.paypal.com"
9
+ SANDBOX_AUTHORIZE_URL = 'https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'
10
+
11
+ option :client_options, {
12
+ :site => 'https://api.paypal.com',
13
+ :authorize_url => 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize',
14
+ :token_url => '/v1/identity/openidconnect/tokenservice',
15
+ :setup => true
16
+ }
17
+
18
+ option :authorize_options, [:scope, :response_type]
19
+ option :provider_ignores_state, true
20
+ option :sandbox, false
21
+
22
+ uid { @parsed_uid ||= (/\/([^\/]+)\z/.match raw_info['user_id'])[1] } #https://www.paypal.com/webapps/auth/identity/user/baCNqjGvIxzlbvDCSsfhN3IrQDtQtsVr79AwAjMxekw => baCNqjGvIxzlbvDCSsfhN3IrQDtQtsVr79AwAjMxekw
23
+
24
+ info do
25
+ prune!({
26
+ 'name' => raw_info['name'],
27
+ 'email' => raw_info['email'],
28
+ 'first_name' => raw_info['given_name'],
29
+ 'last_name' => raw_info['family_name'],
30
+ 'given_name' => raw_info['given_name'],
31
+ 'family_name' => raw_info['family_name'],
32
+ 'location' => (raw_info['address'] || {})['locality'],
33
+ 'phone' => raw_info['phone_number']
34
+ })
35
+ end
36
+
37
+ extra do
38
+ prune!({
39
+ 'account_type' => raw_info['account_type'],
40
+ 'user_id' => raw_info['user_id'],
41
+ 'address' => raw_info['address'],
42
+ 'verified_account' => (raw_info['verified_account'] == 'true'),
43
+ 'language' => raw_info['language'],
44
+ 'zoneinfo' => raw_info['zoneinfo'],
45
+ 'locale' => raw_info['locale'],
46
+ 'account_creation_date' => raw_info['account_creation_date'],
47
+ 'age_range' => raw_info['age_range'],
48
+ 'birthday' => raw_info['birthday']
49
+ })
50
+ end
51
+
52
+ def setup_phase
53
+ if options.sandbox
54
+ options.client_options[:site] = SANDBOX_SITE
55
+ options.client_options[:authorize_url] = SANDBOX_AUTHORIZE_URL
56
+ end
57
+ super
58
+ end
59
+
60
+ def raw_info
61
+ @raw_info ||= load_identity()
62
+ end
63
+
64
+ def authorize_params
65
+ super.tap do |params|
66
+ params[:scope] ||= DEFAULT_SCOPE
67
+ params[:response_type] ||= DEFAULT_RESPONSE_TYPE
68
+ end
69
+ end
70
+
71
+ private
72
+ def load_identity
73
+ access_token.options[:mode] = :query
74
+ access_token.options[:param_name] = :access_token
75
+ access_token.options[:grant_type] = :authorization_code
76
+ access_token.get('/v1/identity/openidconnect/userinfo', { :params => { :schema => 'openid'}}).parsed || {}
77
+ end
78
+
79
+ def prune!(hash)
80
+ hash.delete_if do |_, value|
81
+ prune!(value) if value.is_a?(Hash)
82
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
83
+ end
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+
90
+ OmniAuth.config.add_camelization 'paypal', 'PayPal'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'omniauth/paypal/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'omniauth-paypal-oauth2'
7
+ s.version = '1.4.0'
8
+ s.authors = ['Jonas Hübotter']
9
+ s.email = ['jonas.huebotter@gmail.com']
10
+ s.summary = 'PayPal Identity strategy for OmniAuth2'
11
+ s.homepage = 'https://github.com/jonhue/omniauth-paypal-oauth2'
12
+ s.license = 'MIT'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ['lib']
18
+
19
+ s.add_runtime_dependency 'omniauth-oauth2', '~> 1.4.0'
20
+
21
+ s.add_development_dependency 'rspec', '~> 2.14'
22
+ s.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-paypal'
3
+
4
+ describe OmniAuth::Strategies::PayPal do
5
+ subject do
6
+ OmniAuth::Strategies::PayPal.new(nil, @options || {})
7
+ end
8
+
9
+ it_should_behave_like 'an oauth2 strategy'
10
+
11
+ describe '#client' do
12
+ it 'has correct PayPal site' do
13
+ expect(subject.client.site).to eq('https://api.paypal.com')
14
+ end
15
+
16
+ it 'has correct PayPal sandbox site' do
17
+ @options = { :sandbox => true }
18
+ subject.setup_phase
19
+ expect(subject.client.site).to eq('https://api.sandbox.paypal.com')
20
+ end
21
+
22
+ it 'has correct authorize url' do
23
+ expect(subject.client.options[:authorize_url]).to eq('https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize')
24
+ end
25
+
26
+ it 'has correct sandbox authorize url' do
27
+ @options = { :sandbox => true }
28
+ subject.setup_phase
29
+ expect(subject.client.options[:authorize_url]).to eq('https://www.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize')
30
+ end
31
+
32
+ it 'has correct token url' do
33
+ expect(subject.client.options[:token_url]).to eq('/v1/identity/openidconnect/tokenservice')
34
+ end
35
+
36
+ it 'runs the setup block if passed one' do
37
+ counter = ''
38
+ @options = { :setup => Proc.new { |env| counter = 'ok' } }
39
+ subject.setup_phase
40
+ expect(counter).to eq("ok")
41
+ end
42
+ end
43
+
44
+ describe '#callback_path' do
45
+ it "has the correct callback path" do
46
+ expect(subject.callback_path).to eq('/auth/paypal/callback')
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'omniauth'
4
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
5
+
6
+ RSpec.configure do |config|
7
+ OmniAuth.config.test_mode = true
8
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ expect(subject.client.options[:authorize_url]).to eq('https://example.com')
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ expect(subject.authorize_params['foo']).to eq('bar')
14
+ expect(subject.authorize_params['baz']).to eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ expect(subject.authorize_params['scope']).to eq('bar')
20
+ expect(subject.authorize_params['foo']).to eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any token params passed in the :token_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ expect(subject.token_params['foo']).to eq('bar')
28
+ expect(subject.token_params['baz']).to eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :token_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ expect(subject.token_params['scope']).to eq('bar')
34
+ expect(subject.token_params['foo']).to eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-paypal-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Hübotter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth-oauth2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - jonas.huebotter@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - Rakefile
67
+ - lib/omniauth-paypal.rb
68
+ - lib/omniauth/paypal.rb
69
+ - lib/omniauth/paypal/version.rb
70
+ - lib/omniauth/strategies/paypal.rb
71
+ - omniauth-paypal-oauth2.gemspec
72
+ - spec/omniauth/strategies/paypal_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/support/shared_examples.rb
75
+ homepage: https://github.com/jonhue/omniauth-paypal-oauth2
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.6.8
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: PayPal Identity strategy for OmniAuth2
99
+ test_files: []