omniauth-bigcommerce 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae29ba3aca8d409d3dd30d0701c87dd328d98657
4
- data.tar.gz: f0adc06fd7a179cd2d1010667890204b8d8d0ce7
3
+ metadata.gz: 2fd32cd52747a4e99dbeb7fa6ac4b940f4efd540
4
+ data.tar.gz: a02adf6795281e1b97256aa74ac14641e4995668
5
5
  SHA512:
6
- metadata.gz: a9656528f068f1c5b7d31e4c69571727d52b16bed0c851a5b1e2205d3f5d5a571d389657a34d1561bef8a0d42ac19a2c2fd960d17ad7953b0f489085ec2f7fd0
7
- data.tar.gz: 8145de6b8825c9762b6f0120532b4d4625a740809c7746f42d6673059abaf64b73e05c19db87e6a33537c8c57e5f37bf5f1da93a185707c2f6c2313be2237596
6
+ metadata.gz: d7d4e9e0b458833e6ac4266669b1716f2c19998fee1ebe81eaac9362b10dfe208b15e0c53ac1827273b6d38d5a3f45c21eb25cdcf835375460b2191e8bbde6a0
7
+ data.tar.gz: cacc7e225d778745ea2d50a4eb1131263ef78d7b58244ec4ea50d8aa11e367d5d24de626d44461357ffe597a2766d257e27f18dfd120e00003b6294be5a6b9b1
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
- # Ignore lockfiles
2
- /Gemfile.lock
3
-
4
- # Ignore test output
5
- /spec/coverage
6
- /spec/reports
1
+ .bundle
2
+ Gemfile.lock
3
+ coverage
4
+ reports
5
+ pkg
6
+ vendor/bundle
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - ruby-head
4
- - 2.1.1
5
- - 2.0.0
6
- - 1.9.3
4
+ - 2.3.1
5
+ - 2.2.5
6
+ - 2.1.10
7
7
  matrix:
8
8
  allow_failures:
9
9
  - rvm: ruby-head
data/Gemfile CHANGED
@@ -1,13 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in omniauth-bigcommerce.gemspec
4
3
  gemspec
5
-
6
- group :development, :test do
7
- gem 'rake'
8
- gem 'guard'
9
- gem 'guard-rspec'
10
- gem 'guard-bundler'
11
- gem 'rb-fsevent'
12
- gem 'growl'
13
- end
@@ -1,2 +1,2 @@
1
- require "omniauth/bigcommerce/version"
1
+ require 'omniauth/bigcommerce/version'
2
2
  require 'omniauth/strategies/bigcommerce'
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
- module Bigcommerce
3
- VERSION = "0.2.0"
2
+ module BigCommerce
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -2,15 +2,13 @@ require 'omniauth-oauth2'
2
2
 
3
3
  module OmniAuth
4
4
  module Strategies
5
- class Bigcommerce < OmniAuth::Strategies::OAuth2
6
- option :name, "bigcommerce"
7
-
5
+ class BigCommerce < OmniAuth::Strategies::OAuth2
6
+ option :name, 'bigcommerce'
8
7
  option :provider_ignores_state, true
9
-
10
- option :scope, "users_basic_information"
11
-
12
- option :client_options,
13
- {
8
+ option :scope, 'users_basic_information'
9
+ option :authorize_options, [:scope, :context]
10
+ option :token_options, [:scope, :context]
11
+ option :client_options, {
14
12
  site: ENV['BC_AUTH_SERVICE'] || 'https://login.bigcommerce.com',
15
13
  authorize_url: '/oauth2/authorize',
16
14
  token_url: '/oauth2/token'
@@ -27,7 +25,7 @@ module OmniAuth
27
25
 
28
26
  credentials do
29
27
  {
30
- :token => access_token
28
+ token: access_token
31
29
  }
32
30
  end
33
31
 
@@ -43,8 +41,32 @@ module OmniAuth
43
41
  @raw_info ||= access_token.params
44
42
  end
45
43
 
44
+ # Exclude query string in callback url. This used to be part of omniauth-oauth2, but was
45
+ # removed in 1.4.0: https://github.com/intridea/omniauth-oauth2/pull/70
46
+ def callback_url
47
+ full_host + script_name + callback_path
48
+ end
49
+
50
+ # Make sure to pass scope and context through to the authorize call
51
+ # https://github.com/zquestz/omniauth-google-oauth2/blob/master/lib/omniauth/strategies/google_oauth2.rb#L26
52
+ def authorize_params
53
+ super.tap do |params|
54
+ options[:authorize_options].each do |k|
55
+ params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
56
+ end
57
+ end
58
+ end
59
+
60
+ # Make sure to pass scope and context through to the token exchange call
61
+ def token_params
62
+ super.tap do |params|
63
+ options[:token_options].each do |k|
64
+ params[k] = request.params[k.to_s] unless [nil, ''].include?(request.params[k.to_s])
65
+ end
66
+ end
67
+ end
46
68
  end
47
69
  end
48
70
  end
49
71
 
50
- OmniAuth.config.add_camelization 'bigcommerce', 'Bigcommerce'
72
+ OmniAuth.config.add_camelization 'bigcommerce', 'BigCommerce'
@@ -4,8 +4,8 @@ require File.expand_path('../lib/omniauth/bigcommerce/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Tom Allen, Phil Muir, Sasha Gerrand"]
6
6
  gem.email = ["developer@bigcommerce.com"]
7
- gem.description = %q{Official OmniAuth strategy for Bigcommerce.}
8
- gem.summary = %q{Official OmniAuth strategy for Bigcommerce.}
7
+ gem.description = %q{Official OmniAuth strategy for BigCommerce.}
8
+ gem.summary = %q{Official OmniAuth strategy for BigCommerce.}
9
9
  gem.homepage = "https://github.com/bigcommerce/omniauth-bigcommerce"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -13,13 +13,12 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = "omniauth-bigcommerce"
15
15
  gem.require_paths = ["lib"]
16
- gem.version = OmniAuth::Bigcommerce::VERSION
16
+ gem.required_ruby_version = '>= 2.1'
17
+ gem.version = OmniAuth::BigCommerce::VERSION
17
18
 
18
- gem.add_dependency 'omniauth', '~> 1.0'
19
- gem.add_dependency 'omniauth-oauth2', '~> 1.1'
20
- gem.add_development_dependency 'rake', '~> 2.7'
21
- gem.add_development_dependency 'rspec', '~> 2.7'
22
- gem.add_development_dependency 'rack-test'
19
+ gem.add_dependency 'omniauth'
20
+ gem.add_dependency 'omniauth-oauth2', '>= 1.1.1'
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
23
  gem.add_development_dependency 'simplecov'
24
- gem.add_development_dependency 'webmock'
25
24
  end
@@ -1,40 +1,76 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe OmniAuth::Strategies::Bigcommerce do
3
+ RSpec.describe OmniAuth::Strategies::BigCommerce do
4
+ let(:store_hash) { 'abcdefg' }
5
+ let(:context) { "stores/#{store_hash}" }
6
+ let(:scope) { 'store_v2_products' }
7
+ let(:request) { double('Request', :params => { 'context' => context, 'scope' => scope }, :cookies => {}, :env => {}) }
4
8
 
5
- subject do
6
- OmniAuth::Strategies::Bigcommerce.new({})
9
+ before do
10
+ OmniAuth.config.test_mode = true
11
+ allow(subject).to receive(:request).and_return(request)
7
12
  end
13
+ after { OmniAuth.config.test_mode = false }
14
+ subject { OmniAuth::Strategies::BigCommerce.new({}) }
8
15
 
9
- context 'client options' do
16
+ describe 'options' do
10
17
  it 'should have correct name' do
11
18
  expect(subject.options.name).to eq('bigcommerce')
12
19
  end
13
20
 
14
- it 'should have correct site' do
15
- # env variable set in spec_helper.rb
16
- # TODO: change this once we have bigcommerceapp.com url
17
- expect(subject.options.client_options.site).to eq('https://example.com')
18
- end
21
+ describe 'client options' do
22
+ it 'should have correct site' do
23
+ # env variable set in spec_helper.rb
24
+ # TODO: change this once we have bigcommerceapp.com url
25
+ expect(subject.options.client_options.site).to eq('https://example.com')
26
+ end
27
+
28
+ it 'should have correct authorize url' do
29
+ expect(subject.options.client_options.authorize_url).to eq('/oauth2/authorize')
30
+ end
19
31
 
20
- it 'should have correct authorize url' do
21
- expect(subject.options.client_options.authorize_url).to eq('/oauth2/authorize')
32
+ it 'should have correct token url' do
33
+ expect(subject.options.client_options.token_url).to eq('/oauth2/token')
34
+ end
22
35
  end
23
36
 
24
- it 'should have correct token url' do
25
- expect(subject.options.client_options.token_url).to eq('/oauth2/token')
37
+ describe 'OAuth2 settings' do
38
+ it 'should ignore state' do
39
+ expect(subject.options.provider_ignores_state).to eq true
40
+ end
26
41
  end
27
42
  end
28
43
 
29
- context 'oauth2 settings' do
30
- it 'should ignore state' do
31
- expect(subject.options.provider_ignores_state).to eq true
44
+ describe 'callback url' do
45
+ it 'should have the correct path' do
46
+ expect(subject.callback_path).to eq('/auth/bigcommerce/callback')
47
+ end
48
+
49
+ context 'when callback url has a query string' do
50
+ let(:host) { 'https://example.com' }
51
+ let(:query_string) { 'foo=bar' }
52
+ before do
53
+ allow(subject).to receive(:full_host).and_return(host)
54
+ allow(subject).to receive(:script_name).and_return('')
55
+ allow(subject).to receive(:query_string).and_return(query_string)
56
+ end
57
+
58
+ it 'query string should not be included in the callback url' do
59
+ expect(subject.callback_url).to eq("#{host}#{subject.callback_path}")
60
+ expect(subject.callback_url).to_not include(query_string)
61
+ end
32
62
  end
33
63
  end
34
64
 
35
- context 'callback url' do
36
- it 'should have the correct path' do
37
- subject.callback_path.should eq('/auth/bigcommerce/callback')
65
+ describe 'extra params for authorize and token exchange' do
66
+ it 'should set the context and scope parameters in the authorize request' do
67
+ expect(subject.authorize_params['context']).to eq(context)
68
+ expect(subject.authorize_params['scope']).to eq(scope)
69
+ end
70
+
71
+ it 'should set the context and scope parameters in the token request' do
72
+ expect(subject.token_params['context']).to eq(context)
73
+ expect(subject.token_params['scope']).to eq(scope)
38
74
  end
39
75
  end
40
76
  end
data/spec/spec_helper.rb CHANGED
@@ -2,15 +2,12 @@ ENV['BC_AUTH_SERVICE'] = 'https://example.com'
2
2
 
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
- require 'rspec'
6
- require 'rack/test'
7
- require 'webmock/rspec'
8
- require 'omniauth'
5
+
9
6
  require 'omniauth-bigcommerce'
10
7
 
11
8
  RSpec.configure do |config|
12
- config.include WebMock::API
13
- config.include Rack::Test::Methods
14
- config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
9
+ config.color = true
10
+ config.order = :random
11
+ Kernel.srand config.seed
15
12
  end
16
13
 
metadata CHANGED
@@ -1,73 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-bigcommerce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Allen, Phil Muir, Sasha Gerrand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-01 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: omniauth-oauth2
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: 1.1.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: 1.1.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '2.7'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '2.7'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '2.7'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '2.7'
69
- - !ruby/object:Gem::Dependency
70
- name: rack-test
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
45
  - - '>='
@@ -81,7 +53,7 @@ dependencies:
81
53
  - !ruby/object:Gem::Version
82
54
  version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
- name: simplecov
56
+ name: rspec
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - '>='
@@ -95,7 +67,7 @@ dependencies:
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  - !ruby/object:Gem::Dependency
98
- name: webmock
70
+ name: simplecov
99
71
  requirement: !ruby/object:Gem::Requirement
100
72
  requirements:
101
73
  - - '>='
@@ -108,7 +80,7 @@ dependencies:
108
80
  - - '>='
109
81
  - !ruby/object:Gem::Version
110
82
  version: '0'
111
- description: Official OmniAuth strategy for Bigcommerce.
83
+ description: Official OmniAuth strategy for BigCommerce.
112
84
  email:
113
85
  - developer@bigcommerce.com
114
86
  executables: []
@@ -138,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
110
  requirements:
139
111
  - - '>='
140
112
  - !ruby/object:Gem::Version
141
- version: '0'
113
+ version: '2.1'
142
114
  required_rubygems_version: !ruby/object:Gem::Requirement
143
115
  requirements:
144
116
  - - '>='
@@ -149,7 +121,7 @@ rubyforge_project:
149
121
  rubygems_version: 2.0.14
150
122
  signing_key:
151
123
  specification_version: 4
152
- summary: Official OmniAuth strategy for Bigcommerce.
124
+ summary: Official OmniAuth strategy for BigCommerce.
153
125
  test_files:
154
126
  - spec/omniauth/strategies/bigcommerce_spec.rb
155
127
  - spec/spec_helper.rb