omniauth-paypal-openid 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fc223104652396145b843652f6392b46b627de34
4
+ data.tar.gz: d2a19fa89f7bcc8279f2beb12dd24a7733b9bffd
5
+ SHA512:
6
+ metadata.gz: 671bf6ad3053bce0b658005b8253dfad3657bfb4d1f00c7e52f2b12903bbd73cc41d93c80cdd9d092aed971c2f2ebac6b2d6160d720e8687c00de1ef8908f922
7
+ data.tar.gz: 201d4c111aff1f913dd2e56fb4357d47ae20317cbbcbd14a3b50f2477e7072a93a9225447dc8f383391bbb3dbf9d3d1b996e78432fbfc365a5a3c89581770cad
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kb1990@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'json'
6
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 kbravi
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.
@@ -0,0 +1,130 @@
1
+ # Omniauth PayPal OpenID
2
+
3
+ This gem contains the Log In With PayPal OpenID strategy for OmniAuth.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'omniauth-paypal-openid'
11
+ ```
12
+
13
+ And then execute:
14
+ ```
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```
20
+ $ gem install omniauth-paypal-openid
21
+ ```
22
+
23
+ ## Usage
24
+
25
+
26
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`.
27
+
28
+ ```ruby
29
+ Rails.application.config.middleware.use OmniAuth::Builder do
30
+ provider :paypal_openid, ENV['APP_ID'], ENV['APP_TOKEN'], sandbox: true, scope: "openid profile email"
31
+ end
32
+ ```
33
+
34
+ ## Attributes and Scopes
35
+
36
+ Log In With PayPal information can be found on https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/
37
+
38
+ The possible attributes to be returned at the moment are:
39
+
40
+ ```ruby
41
+ info['name']
42
+ info['email']
43
+ info['first_name']
44
+ info['last_name']
45
+ info['location']
46
+ info['name']
47
+ info['phone']
48
+
49
+ extra['raw_info']['account_creation_date']
50
+ extra['raw_info']['account_type']
51
+ extra['raw_info']['address']['country']
52
+ extra['raw_info']['address']['locality']
53
+ extra['raw_info']['address']['postal_code']
54
+ extra['raw_info']['address']['region']
55
+ extra['raw_info']['address']['street_address']
56
+ extra['raw_info']['language']
57
+ extra['raw_info']['locale']
58
+ extra['raw_info']['verified_account']
59
+ extra['raw_info']['zoneinfo']
60
+ extra['raw_info']['age_range']
61
+ extra['raw_info']['birthday']
62
+ ```
63
+
64
+ The actual set of attributes returned depends on the scopes set. The currently available scopes are:
65
+
66
+ ```
67
+ openid
68
+ profile
69
+ email
70
+ address
71
+ phone
72
+ https://uri.paypal.com/services/paypalattributes
73
+ https://uri.paypal.com/services/expresscheckout
74
+ ```
75
+
76
+ (those last 2 are scope names, not links)
77
+
78
+ For more details see the PayPal [list of attributes](https://developer.paypal.com/webapps/developer/docs/integration/direct/log-in-with-paypal/detailed/#attributes).
79
+
80
+ ## Registering for an API key
81
+
82
+ 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.
83
+
84
+ ## Example of result auth hash
85
+ With all scopes requested.
86
+
87
+ ```yaml
88
+ provider: paypal
89
+ uid: bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
90
+ info:
91
+ name: John Smith
92
+ email: example@example.com
93
+ first_name: John
94
+ last_name: Smith
95
+ location: Moscow
96
+ name: John Smith
97
+ phone: "71234567890"
98
+ credentials:
99
+ token: <token>
100
+ refresh_token: <refresh token>
101
+ expires_at: 1355082790
102
+ expires: true
103
+ extra:
104
+ raw_info:
105
+ account_creation_date: "2008-04-21"
106
+ account_type: PERSONAL
107
+ user_id: https://www.paypal.com/webapps/auth/identity/user/bathjJwvdhKjgfgh8Jd745J7dh5Qkgflbnczd65dfnw
108
+ address:
109
+ country: US
110
+ locality: San Jose
111
+ postal_code: "95131"
112
+ region: CA
113
+ street_address: 1 Main St
114
+ language: en_US
115
+ locale: en_US
116
+ verified_account: true
117
+ zoneinfo: America/Los_Angeles
118
+ age_range: 31-35
119
+ birthday: "1982-01-01"
120
+ ```
121
+
122
+ ## Contributing
123
+
124
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/omniauth-paypal-openid. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
125
+
126
+
127
+ ## License
128
+
129
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
130
+
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "omniauth/paypal/openid"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,2 @@
1
+ require 'omniauth-paypal-openid/version'
2
+ require 'omniauth/strategies/paypal-openid'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module PayPalOpenID
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,112 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class PayPalOpenID < 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 :name, 'paypal_openid'
12
+ option :client_options, {
13
+ :site => 'https://api.paypal.com',
14
+ :authorize_url => 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize',
15
+ :token_url => '/v1/identity/openidconnect/tokenservice',
16
+ }
17
+
18
+ option :authorize_options, [:scope, :response_type, :redirect_uri]
19
+ option :provider_ignores_state, true
20
+ option :sandbox, false
21
+
22
+ uid { @parsed_uid ||= (/\/([^\/]+)\z/.match raw_info['user_id'])[1] }
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
+ location: build_user_location,
31
+ phone: raw_info['phone_number'],
32
+ image: raw_info['picture']
33
+ })
34
+ end
35
+
36
+ extra do
37
+ prune!({'raw_info' => raw_info})
38
+ end
39
+
40
+ def setup_phase
41
+ if options.sandbox
42
+ options.client_options[:site] = SANDBOX_SITE
43
+ options.client_options[:authorize_url] = SANDBOX_AUTHORIZE_URL
44
+ end
45
+ super
46
+ end
47
+
48
+ def callback_url
49
+ options[:redirect_uri] || (full_host + script_name + callback_path)
50
+ end
51
+
52
+ def raw_info
53
+ @raw_info ||= load_identity
54
+ end
55
+
56
+ def authorize_params
57
+ super.tap do |params|
58
+ params[:scope] ||= DEFAULT_SCOPE
59
+ params[:response_type] ||= DEFAULT_RESPONSE_TYPE
60
+ end
61
+ end
62
+
63
+ def custom_build_access_token
64
+ access_token =
65
+ if request.xhr? && request.params['code']
66
+ verifier = request.params['code']
67
+ redirect_uri = request.params['redirect_uri'] || 'postmessage'
68
+ client.auth_code.get_token(verifier, get_token_options(redirect_uri), deep_symbolize(options.auth_token_params || {}))
69
+ elsif request.params['code'] && request.params['redirect_uri']
70
+ verifier = request.params['code']
71
+ redirect_uri = request.params['redirect_uri']
72
+ client.auth_code.get_token(verifier, get_token_options(redirect_uri), deep_symbolize(options.auth_token_params || {}))
73
+ else
74
+ verifier = request.params["code"]
75
+ client.auth_code.get_token(verifier, get_token_options(callback_url), deep_symbolize(options.auth_token_params))
76
+ end
77
+ access_token
78
+ end
79
+ alias_method :build_access_token, :custom_build_access_token
80
+
81
+ private
82
+
83
+ def load_identity
84
+ access_token.options[:mode] = :query
85
+ access_token.options[:param_name] = :access_token
86
+ access_token.options[:grant_type] = :authorization_code
87
+ access_token.get('/v1/identity/openidconnect/userinfo', { :params => { :schema => 'openid'}}).parsed || {}
88
+ end
89
+
90
+ def get_token_options(redirect_uri)
91
+ { :redirect_uri => redirect_uri }.merge(token_params.to_hash(:symbolize_keys => true))
92
+ end
93
+
94
+ def prune!(hash)
95
+ hash.delete_if do |_, value|
96
+ prune!(value) if value.is_a?(Hash)
97
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
98
+ end
99
+ end
100
+
101
+ def build_user_location
102
+ return unless raw_info['address']
103
+ location = [
104
+ raw_info['address']['locality'],
105
+ raw_info['address']['region']
106
+ ].compact.join(', ')
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ OmniAuth.config.add_camelization 'paypal_openid', 'PayPalOpenID'
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-paypal-openid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-paypal-openid"
8
+ spec.version = OmniAuth::PayPalOpenID::VERSION
9
+ spec.authors = ["Karthik Ravichandran"]
10
+ spec.email = ["kb1990@gmail.com"]
11
+
12
+ spec.summary = %q{PayPal Identity strategy for OmniAuth}
13
+ spec.homepage = "https://github.com/kbravi/omniauth-paypal-openid"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency 'omniauth', '>= 1.1.1'
24
+ spec.add_runtime_dependency 'omniauth-oauth2', '>= 1.3.1'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-paypal-openid
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Karthik Ravichandran
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-11 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: 1.1.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.1
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.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description:
84
+ email:
85
+ - kb1990@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/omniauth-paypal-openid.rb
101
+ - lib/omniauth-paypal-openid/version.rb
102
+ - lib/omniauth/strategies/paypal-openid.rb
103
+ - omniauth-paypal-openid.gemspec
104
+ homepage: https://github.com/kbravi/omniauth-paypal-openid
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.8
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: PayPal Identity strategy for OmniAuth
128
+ test_files: []