omniauth-amazon-sp-api 1.0.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 262bb72940b3ee5ee101604beebc60d2a97fc3d153818b7a70970fea418cd161
4
+ data.tar.gz: ea3390764afd5ac8424d4f951924aaee7eccc98987fd892536b84962539e6f03
5
+ SHA512:
6
+ metadata.gz: 3d706e43f790d844434391d23b983f2fc6703d65a6ddf1f6c18e57b3305ea898e05610f46a7e6d74f21d54fe35fcc91420c445428efbb436fb2b472486587ea4
7
+ data.tar.gz: 380db0e148ef4dd778ddefbc66e7f510cab3c9de1b65f771cde56df84cb9646f3221b491382fcf4b21ea44922b90f0da9e44e887ecf81e8a14256fc91175fbd6
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 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ sudo: false
2
+ rvm:
3
+ - 3.0.2
4
+ - 2.7.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-amazon.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # OmniAuth::AmazonSpApi
2
+
3
+ Website authorization flow for Amazon Selling Partner APIs.
4
+
5
+ https://github.com/amzn/selling-partner-api-docs/blob/main/guides/en-US/developer-guide/SellingPartnerApiDeveloperGuide.md#website-authorization-workflow
6
+
7
+ # Configuration
8
+
9
+ Here's an example for adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
10
+
11
+ ```ruby
12
+ Rails.application.config.middleware.use OmniAuth::Builder do
13
+ provider :amazon_sp_api, ENV['AMAZON_SP_API_CLIENT_ID'], ENV['AMAZON_SP_API_CLIENT_SECRET'],
14
+ redirect_uri: "https://example.com/auth/amazon_sp_api/callback", # if you need to override the default URL generated by the gem
15
+ authorize_params: {
16
+ application_id: ENV['AMAZON_SP_API_APPLICATION_ID'],
17
+ version: 'beta', # If you app is in Draft state, this is required.
18
+ },
19
+ client_options: {
20
+ authorize_url: 'https://sellercentral.amazon.com/apps/authorize/consent',
21
+ site: Rails.env.production? ? 'https://sellingpartnerapi-na.amazon.com' : 'https://sandbox.sellingpartnerapi-na.amazon.com'
22
+ }
23
+ end
24
+ ```
25
+
26
+ ## Using devise
27
+
28
+ Here's an example if you are using Devise. Add this to `config/initializers/devise.rb`:
29
+
30
+ ```ruby
31
+ config.omniauth :amazon_sp_api, ENV['AMAZON_SP_API_CLIENT_ID'], ENV['AMAZON_SP_API_CLIENT_SECRET'], {
32
+ redirect_uri: "https://example.com/auth/amazon_sp_api/callback", # if you need to override the default URL generated by the gem
33
+ authorize_params: {
34
+ application_id: ENV['AMAZON_SP_API_APPLICATION_ID'],
35
+ version: 'beta', # If you app is in Draft state, this is required.
36
+ },
37
+ }
38
+ ```
39
+
40
+ Then update your `User` model:
41
+
42
+ ```ruby
43
+ devise(
44
+ # Other Devise options
45
+ omniauth_providers: [:amazon_sp_api],
46
+ )
47
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module AmazonSpApi
3
+ VERSION = '1.0.2'.freeze
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require "omniauth/amazon-sp-api/version"
2
+ require "omniauth/strategies/amazon-sp-api"
3
+
@@ -0,0 +1,46 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class AmazonSpApi < OmniAuth::Strategies::OAuth2
6
+ attr_reader :selling_partner_id, :mws_auth_token
7
+
8
+ option :name, 'amazon_sp_api'
9
+
10
+ option :client_options,
11
+ {
12
+ site: 'https://sellingpartnerapi-na.amazon.com',
13
+ authorize_url: 'https://sellercentral.amazon.com/apps/authorize/consent',
14
+ token_url: 'https://api.amazon.com/auth/o2/token'
15
+ }
16
+
17
+ extra do
18
+ {
19
+ 'selling_partner_id' => selling_partner_id,
20
+ 'mws_auth_token' => mws_auth_token
21
+ }
22
+ end
23
+
24
+ def callback_phase
25
+ @selling_partner_id = request.params['selling_partner_id']
26
+ @mws_auth_token = request.params['mws_auth_token']
27
+ super
28
+ end
29
+
30
+ def build_access_token
31
+ verifier = request.params['spapi_oauth_code']
32
+ client.auth_code.get_token(
33
+ verifier,
34
+ { redirect_uri: callback_url }.merge(
35
+ token_params.to_hash(symbolize_keys: true)
36
+ ),
37
+ deep_symbolize(options.auth_token_params)
38
+ )
39
+ end
40
+
41
+ def callback_url
42
+ options[:redirect_uri] || full_host + script_name + callback_path
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/amazon-sp-api'
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/amazon-sp-api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-amazon-sp-api"
8
+ spec.version = OmniAuth::AmazonSpApi::VERSION
9
+ spec.authors = ["Dropstream"]
10
+ spec.email = ["karl.falconer@getdropstream.com"]
11
+ spec.description = %q{Amazon Selling Partner API strategy}
12
+ spec.summary = %q{Amazon Selling Partner API strategy}
13
+ spec.homepage = "https://github.com/dropstream/omniauth-amazon-sp-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'omniauth', '~> 1.0'
22
+ spec.add_dependency 'omniauth-oauth2', '~> 1.1'
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency 'rspec', '~> 3.10'
27
+ spec.add_development_dependency 'rack-test'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'pry-byebug'
31
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+ require 'support/shared_examples'
3
+
4
+ describe OmniAuth::Strategies::AmazonSpApi do
5
+ subject(:strategy) do
6
+ strategy = OmniAuth::Strategies::AmazonSpApi.new(nil, nil, options)
7
+ strategy.stub(:session) { {} }
8
+ strategy
9
+ end
10
+
11
+ let(:options) { {} }
12
+
13
+ include_examples 'an oauth2 strategy'
14
+
15
+ describe '#client' do
16
+ subject(:client) { strategy.client }
17
+
18
+ it 'should have the correct Amazon site' do
19
+ expect(client.site).to eq 'https://sellingpartnerapi-na.amazon.com'
20
+ end
21
+
22
+ it 'should have the correct authorization url' do
23
+ expect(client.options[:authorize_url]).to eq(
24
+ 'https://sellercentral.amazon.com/apps/authorize/consent'
25
+ )
26
+ end
27
+
28
+ it 'should have the correct token url' do
29
+ expect(client.options[:token_url]).to eq(
30
+ 'https://api.amazon.com/auth/o2/token'
31
+ )
32
+ end
33
+ end
34
+
35
+ describe '#callback_path' do
36
+ subject(:callback_path) { strategy.callback_path }
37
+
38
+ it 'should have the correct callback path' do
39
+ expect(callback_path).to eq '/auth/amazon_sp_api/callback'
40
+ end
41
+ end
42
+
43
+ describe '#callback_url' do
44
+ subject(:callback_url) { strategy.callback_url }
45
+
46
+ it 'does not include query parameters' do
47
+ allow(strategy).to receive(:full_host).and_return('https://example.com')
48
+ allow(strategy).to receive(:script_name).and_return('/sub_uri')
49
+ allow(strategy).to receive(:query_string).and_return('?foo=bar')
50
+
51
+ expect(callback_url).to eq 'https://example.com/sub_uri/auth/amazon_sp_api/callback'
52
+ end
53
+
54
+ context 'when a redirect_uri option is informed' do
55
+ let(:options) { { redirect_uri: "https://example.com/auth/amazon_sp_api/callback" } }
56
+
57
+ it 'returns the redirect_uri' do
58
+ expect(callback_url).to eq options[:redirect_uri]
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-amazon-sp-api'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+ end
@@ -0,0 +1,72 @@
1
+ # Courtesy omniauth-37signals:
2
+ # https://github.com/tallgreentree/omniauth-37signals/blob/master/spec/support/shared_examples.rb
3
+
4
+ shared_examples 'an oauth2 strategy' do
5
+ describe '#client' do
6
+ subject(:client) { strategy.client}
7
+
8
+ context 'with client_options informed' do
9
+ let(:options) do
10
+ {
11
+ client_options: { 'authorize_url' => 'https://example.com' }
12
+ }
13
+ end
14
+
15
+ it 'should be initialized with symbolized client_options' do
16
+ expect(client.options[:authorize_url]).to eq 'https://example.com'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe '#authorize_params' do
22
+ subject(:authorize_params) { strategy.authorize_params}
23
+
24
+ context 'with authorized_params option' do
25
+ let(:options) do
26
+ { authorize_params: { foo: 'bar', baz: 'zip' } }
27
+ end
28
+
29
+ it 'should include any authorize params passed in the :authorize_params option' do
30
+ expect(authorize_params['foo']).to eq 'bar'
31
+ expect(authorize_params['baz']).to eq 'zip'
32
+ end
33
+ end
34
+
35
+ context 'with top-level options marked as authorized_options' do
36
+ let(:options) do
37
+ { authorize_options: %i[scope foo], scope: 'bar', foo: 'baz' }
38
+ end
39
+
40
+ it 'should include top-level options that are marked as :authorize_options' do
41
+ expect(authorize_params['scope']).to eq 'bar'
42
+ expect(authorize_params['foo']).to eq 'baz'
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#token_params' do
48
+ subject(:token_params) { strategy.token_params}
49
+
50
+ context 'with token_params option' do
51
+ let(:options) do
52
+ { token_params: { foo: 'bar', baz: 'zip' } }
53
+ end
54
+
55
+ it 'should include any authorize params passed in the :token_params option' do
56
+ expect(token_params['foo']).to eq 'bar'
57
+ expect(token_params['baz']).to eq 'zip'
58
+ end
59
+ end
60
+
61
+ context 'with top-level options marked as authorized_options' do
62
+ let(:options) do
63
+ { token_options: %i[scope foo], scope: 'bar', foo: 'baz' }
64
+ end
65
+
66
+ it 'should include top-level options that are marked as :token_options' do
67
+ expect(token_params['scope']).to eq 'bar'
68
+ expect(token_params['foo']).to eq 'baz'
69
+ end
70
+ end
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-amazon-sp-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Dropstream
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-08 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.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.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.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.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: '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
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Amazon Selling Partner API strategy
140
+ email:
141
+ - karl.falconer@getdropstream.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - lib/omniauth-amazon-sp-api.rb
154
+ - lib/omniauth/amazon-sp-api.rb
155
+ - lib/omniauth/amazon-sp-api/version.rb
156
+ - lib/omniauth/strategies/amazon-sp-api.rb
157
+ - omniauth-amazon-sp-api.gemspec
158
+ - spec/omniauth/strategies/amazon-sp-api_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/shared_examples.rb
161
+ homepage: https://github.com/dropstream/omniauth-amazon-sp-api
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubygems_version: 3.4.1
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: Amazon Selling Partner API strategy
184
+ test_files:
185
+ - spec/omniauth/strategies/amazon-sp-api_spec.rb
186
+ - spec/spec_helper.rb
187
+ - spec/support/shared_examples.rb