omniauth-paypal 1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -0
- data/Gemfile.lock +58 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/lib/omniauth/paypal/version.rb +5 -0
- data/lib/omniauth/paypal.rb +2 -0
- data/lib/omniauth/strategies/paypal.rb +81 -0
- data/lib/omniauth-paypal.rb +1 -0
- data/omniauth-paypal.gemspec +23 -0
- data/spec/omniauth/strategies/paypal_spec.rb +37 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/shared_examples.rb +37 -0
- metadata +109 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/intridea/omniauth-oauth2.git
|
3
|
+
revision: d6409bb14337675e22c50f3c76b5d7f672a631a3
|
4
|
+
specs:
|
5
|
+
omniauth-oauth2 (1.1.1)
|
6
|
+
oauth2 (~> 0.9.0)
|
7
|
+
omniauth (~> 1.0)
|
8
|
+
|
9
|
+
PATH
|
10
|
+
remote: .
|
11
|
+
specs:
|
12
|
+
omniauth-paypal (1.0)
|
13
|
+
omniauth-oauth2 (~> 1.1.0)
|
14
|
+
|
15
|
+
GEM
|
16
|
+
remote: https://rubygems.org/
|
17
|
+
specs:
|
18
|
+
diff-lcs (1.1.3)
|
19
|
+
faraday (0.8.6)
|
20
|
+
multipart-post (~> 1.1)
|
21
|
+
hashie (1.2.0)
|
22
|
+
httpauth (0.2.0)
|
23
|
+
json (1.6.6)
|
24
|
+
jwt (0.1.5)
|
25
|
+
multi_json (>= 1.0)
|
26
|
+
multi_json (1.6.1)
|
27
|
+
multi_xml (0.5.3)
|
28
|
+
multipart-post (1.2.0)
|
29
|
+
oauth2 (0.9.1)
|
30
|
+
faraday (~> 0.8)
|
31
|
+
httpauth (~> 0.1)
|
32
|
+
jwt (~> 0.1.4)
|
33
|
+
multi_json (~> 1.0)
|
34
|
+
multi_xml (~> 0.5)
|
35
|
+
rack (~> 1.2)
|
36
|
+
omniauth (1.1.3)
|
37
|
+
hashie (~> 1.2)
|
38
|
+
rack
|
39
|
+
rack (1.5.2)
|
40
|
+
rake (0.9.2.2)
|
41
|
+
rspec (2.7.0)
|
42
|
+
rspec-core (~> 2.7.0)
|
43
|
+
rspec-expectations (~> 2.7.0)
|
44
|
+
rspec-mocks (~> 2.7.0)
|
45
|
+
rspec-core (2.7.1)
|
46
|
+
rspec-expectations (2.7.0)
|
47
|
+
diff-lcs (~> 1.1.2)
|
48
|
+
rspec-mocks (2.7.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
ruby
|
52
|
+
|
53
|
+
DEPENDENCIES
|
54
|
+
json
|
55
|
+
omniauth-oauth2 (~> 1.1.1)!
|
56
|
+
omniauth-paypal!
|
57
|
+
rake
|
58
|
+
rspec (~> 2.7.0)
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# OmniAuth PayPal
|
2
|
+
|
3
|
+
**Note:** This gem is designed to work with OmniAuth 1.0 library.
|
4
|
+
|
5
|
+
This gem contains the PayPal Access using OpenID strategy for OmniAuth.
|
6
|
+
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
Add to your `Gemfile`:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omniauth-paypal', :git => "git://github.com/datariot/omniauth-paypal.git"
|
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']
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
## info
|
28
|
+
|
29
|
+
PayPal Access information https://www.x.com/developers/x.commerce/products/paypal-access
|
30
|
+
|
31
|
+
The maximum info returned currently is:
|
32
|
+
|
33
|
+
info['name']
|
34
|
+
info['email']
|
35
|
+
info['first_name']
|
36
|
+
info['last_name]
|
37
|
+
info['location']
|
38
|
+
info['phone']
|
39
|
+
|
40
|
+
extra['account_type']
|
41
|
+
extra['user_id']
|
42
|
+
extra['address']['postal_code']
|
43
|
+
extra['address']['locality']
|
44
|
+
extra['address']['country']
|
45
|
+
extra['address']['street_address']
|
46
|
+
extra['verified_account']
|
47
|
+
extra['language']
|
48
|
+
extra['zoneinfo']
|
49
|
+
extra['locale']
|
50
|
+
extra['account_creation_date']
|
51
|
+
|
52
|
+
PayPal docs claim that day of birth also may be returned, but I was not able to find this param name, so it's not currently included.
|
53
|
+
|
54
|
+
Actual set of attributes depends on these possible scopes:
|
55
|
+
|
56
|
+
openid
|
57
|
+
profile
|
58
|
+
email
|
59
|
+
address
|
60
|
+
phone
|
61
|
+
https://uri.paypal.com/services/paypalattributes
|
62
|
+
(the last is scope name, not a link)
|
63
|
+
|
64
|
+
For details see [this section](https://www.x.com/developers/paypal/documentation-tools/quick-start-guides/oauth-openid-connect-integration-paypal##attributes).
|
65
|
+
|
66
|
+
To register your application for PayPal Access follow these instructions: https://www.x.com/developers/paypal/how-to-guides/how-register-application-paypal-access
|
67
|
+
|
68
|
+
|
69
|
+
## Example of result auth hash
|
70
|
+
With all scopes requested.
|
71
|
+
|
72
|
+
provider: paypal
|
73
|
+
uid: bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
|
74
|
+
info:
|
75
|
+
name: John Smith
|
76
|
+
email: example@example.com
|
77
|
+
first_name: John
|
78
|
+
last_name: Smith
|
79
|
+
location: Moscow
|
80
|
+
phone: "71234567890"
|
81
|
+
credentials:
|
82
|
+
token: <token>
|
83
|
+
refresh_token: <refresh token>
|
84
|
+
expires_at: 1355082790
|
85
|
+
expires: true
|
86
|
+
extra:
|
87
|
+
account_type: PERSONAL
|
88
|
+
user_id: https://www.paypal.com/webapps/auth/identity/user/bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
|
89
|
+
address:
|
90
|
+
postal_code: "123456"
|
91
|
+
locality: Moscow
|
92
|
+
country: RU
|
93
|
+
street_address: Red square, 1
|
94
|
+
verified_account: "true"
|
95
|
+
language: en_US
|
96
|
+
zoneinfo: America/Los_Angeles
|
97
|
+
locale: en_US
|
98
|
+
account_creation_date: "2008-04-21"
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
Copyright (c) 2011 by veloGraf Systems
|
103
|
+
|
104
|
+
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:
|
105
|
+
|
106
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
107
|
+
|
108
|
+
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,81 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class PayPal < OmniAuth::Strategies::OAuth2
|
6
|
+
DEFAULT_SCOPE = "profile"
|
7
|
+
DEFAULT_RESPONSE_TYPE = "code"
|
8
|
+
SANDBOX_SITE = "https://www.sandbox.paypal.com"
|
9
|
+
|
10
|
+
option :client_options, {
|
11
|
+
:site => 'https://www.paypal.com',
|
12
|
+
:authorize_url => '/webapps/auth/protocol/openidconnect/v1/authorize',
|
13
|
+
:token_url => '/webapps/auth/protocol/openidconnect/v1/tokenservice',
|
14
|
+
:setup => true
|
15
|
+
}
|
16
|
+
|
17
|
+
option :authorize_options, [:scope, :response_type]
|
18
|
+
option :provider_ignores_state, true
|
19
|
+
option :sandbox, false
|
20
|
+
|
21
|
+
uid { @parsed_uid ||= (/\/([^\/]+)\z/.match raw_info['user_id'])[1] } #https://www.paypal.com/webapps/auth/identity/user/baCNqjGvIxzlbvDCSsfhN3IrQDtQtsVr79AwAjMxekw => baCNqjGvIxzlbvDCSsfhN3IrQDtQtsVr79AwAjMxekw
|
22
|
+
|
23
|
+
info do
|
24
|
+
prune!({
|
25
|
+
'name' => raw_info['name'],
|
26
|
+
'email' => raw_info['email'],
|
27
|
+
'first_name' => raw_info['given_name'],
|
28
|
+
'last_name' => raw_info['family_name'],
|
29
|
+
'location' => (raw_info['address'] || {})['locality'],
|
30
|
+
'phone' => raw_info['phone_number']
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
extra do
|
35
|
+
prune!({
|
36
|
+
'account_type' => raw_info['account_type'],
|
37
|
+
'user_id' => raw_info['user_id'],
|
38
|
+
'address' => raw_info['address'],
|
39
|
+
'verified_account' => raw_info['verified_account'],
|
40
|
+
'language' => raw_info['language'],
|
41
|
+
'zoneinfo' => raw_info['zoneinfo'],
|
42
|
+
'locale' => raw_info['locale'],
|
43
|
+
'account_creation_date' => raw_info['account_creation_date']
|
44
|
+
})
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup_phase
|
48
|
+
options.client_options[:site] = SANDBOX_SITE if options.sandbox
|
49
|
+
end
|
50
|
+
|
51
|
+
def raw_info
|
52
|
+
@raw_info ||= load_identity()
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorize_params
|
56
|
+
super.tap do |params|
|
57
|
+
params[:scope] ||= DEFAULT_SCOPE
|
58
|
+
params[:response_type] ||= DEFAULT_RESPONSE_TYPE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def load_identity
|
64
|
+
access_token.options[:mode] = :query
|
65
|
+
access_token.options[:param_name] = :access_token
|
66
|
+
access_token.options[:grant_type] = :authorization_code
|
67
|
+
access_token.get('/webapps/auth/protocol/openidconnect/v1/userinfo', { :params => { :schema => 'openid'}}).parsed || {}
|
68
|
+
end
|
69
|
+
|
70
|
+
def prune!(hash)
|
71
|
+
hash.delete_if do |_, value|
|
72
|
+
prune!(value) if value.is_a?(Hash)
|
73
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
OmniAuth.config.add_camelization 'paypal', 'PayPal'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/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'
|
7
|
+
s.version = OmniAuth::PayPal::VERSION
|
8
|
+
s.authors = ['David W. Allen']
|
9
|
+
s.email = ['david@datariot.io']
|
10
|
+
s.summary = 'PayPal Identity strategy for OmniAuth'
|
11
|
+
s.homepage = 'https://github.com/datariot/omniauth-paypal'
|
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.1.0'
|
20
|
+
|
21
|
+
s.add_development_dependency 'rspec', '~> 2.7.0'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
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
|
+
subject.client.site.should eq('https://www.paypal.com')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has correct PayPal sandbox site' do
|
17
|
+
@options = { :sandbox => true }
|
18
|
+
subject.setup_phase
|
19
|
+
subject.client.site.should eq('https://www.sandbox.paypal.com')
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has correct authorize url' do
|
23
|
+
subject.client.options[:authorize_url].should eq('/webapps/auth/protocol/openidconnect/v1/authorize')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'has correct token url' do
|
27
|
+
subject.client.options[:token_url].should eq('/webapps/auth/protocol/openidconnect/v1/tokenservice')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#callback_path' do
|
32
|
+
it "has the correct callback path" do
|
33
|
+
subject.callback_path.should eq('/auth/paypal/callback')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -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
|
+
subject.client.options[:authorize_url].should == '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
|
+
subject.authorize_params['foo'].should eq('bar')
|
14
|
+
subject.authorize_params['baz'].should 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
|
+
subject.authorize_params['scope'].should eq('bar')
|
20
|
+
subject.authorize_params['foo'].should 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
|
+
subject.token_params['foo'].should eq('bar')
|
28
|
+
subject.token_params['baz'].should 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
|
+
subject.token_params['scope'].should eq('bar')
|
34
|
+
subject.token_params['foo'].should eq('baz')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-paypal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- David W. Allen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-08-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.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.1.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.7.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.7.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '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: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- david@datariot.io
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- Gemfile
|
70
|
+
- Gemfile.lock
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/omniauth-paypal.rb
|
74
|
+
- lib/omniauth/paypal.rb
|
75
|
+
- lib/omniauth/paypal/version.rb
|
76
|
+
- lib/omniauth/strategies/paypal.rb
|
77
|
+
- omniauth-paypal.gemspec
|
78
|
+
- spec/omniauth/strategies/paypal_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
- spec/support/shared_examples.rb
|
81
|
+
homepage: https://github.com/datariot/omniauth-paypal
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: PayPal Identity strategy for OmniAuth
|
106
|
+
test_files:
|
107
|
+
- spec/omniauth/strategies/paypal_spec.rb
|
108
|
+
- spec/spec_helper.rb
|
109
|
+
- spec/support/shared_examples.rb
|