Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ commands:
- restore_cache:
keys:
- <<parameters.gem_cache_key>>-{{ arch }}-{{ .Branch }}-{{ checksum "omniauth-bigcommerce.gemspec" }}-{{checksum "Gemfile"}}
- <<parameters.gem_cache_key>>-{{ arch }}-{{ .Branch }}
- <<parameters.gem_cache_key>>
- run:
name: "bundle install"
command: |
Expand Down Expand Up @@ -136,7 +134,6 @@ jobs:
- bundle-install:
<<: *gem_cache_key
- rspec-unit

workflows:
version: 2
ruby_2_7:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AllCops:
TargetRubyVersion: 2.1
TargetRubyVersion: 2.7.5
NewCops: enable
SuggestExtensions: false

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Changelog for the omniauth-bigcommerce gem.

### Pending release

- Add support for Ruby 3.0 and above
- Remove support for Ruby < 2.7.5
- Upgrade `oauth2` gem >= 2.0
- Upgrade `omniauth-oauth2` gem to >= 1.7
- Add CircleCI support

### 0.4.0

- Adds account_uuid to response payload
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following response format is provided back to you for this provider:
raw_info: {},
scopes: 'requested_scopes store_v2_settings'
context: 'store/xyz123',
account_uuid: 'fooBar'
account_uuid: '3D2D8C24-8378-4180-9550-69A95ABDFAAF'
}
}
```
Expand Down
11 changes: 11 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'omniauth-bigcommerce'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

require 'irb'
IRB.start(__FILE__)
10 changes: 10 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install
bundle exec rspec -p
bundle exec rubocop -P
bundle audit update
bundle audit
2 changes: 1 addition & 1 deletion lib/omniauth/bigcommerce/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
#
module OmniAuth
module BigCommerce
VERSION = '0.4.1.pre'
VERSION = '1.0.0.pre'
end
end
6 changes: 3 additions & 3 deletions lib/omniauth/strategies/bigcommerce.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class BigCommerce < OmniAuth::Strategies::OAuth2
option :token_options, %i[scope context account_uuid]
option :client_options,
site: ENV.fetch('BC_AUTH_SERVICE', 'https://login.bigcommerce.com'),
authorize_url: '/oauth2/authorize',
token_url: '/oauth2/token'
authorize_url: 'oauth2/authorize',
token_url: 'oauth2/token'
Comment on lines +33 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the default values in later versions of OmniAuth.

Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be. This is the same change done in the upstream gem. I do think we need a PoL before merge though.


uid { access_token.params['user']['id'] }

Expand Down Expand Up @@ -64,7 +64,7 @@ def raw_info
# Exclude query string in callback url. This used to be part of omniauth-oauth2, but was
# removed in 1.4.0: https://github.com/intridea/omniauth-oauth2/pull/70
def callback_url
full_host + script_name + callback_path
full_host + callback_path
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

script_name is part of callback_path and so its redundant to have here.

end

# Make sure to pass scope and context through to the authorize call
Expand Down
6 changes: 3 additions & 3 deletions omniauth-bigcommerce.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Gem::Specification.new do |gem|
gem.files = Dir['README.md', 'lib/**/*', 'omniauth-bigcommerce.gemspec', 'Gemfile']
gem.name = 'omniauth-bigcommerce'
gem.require_paths = ['lib']
gem.required_ruby_version = '>= 2.1'
gem.required_ruby_version = '>= 2.7.5'
gem.version = OmniAuth::BigCommerce::VERSION
gem.license = 'MIT'

gem.add_dependency 'oauth2', '>= 1.4.4'
gem.add_dependency 'oauth2', '>= 2.0.0'
gem.add_dependency 'omniauth'
gem.add_dependency 'omniauth-oauth2', '>= 1.5'
gem.add_dependency 'omniauth-oauth2', '>= 1.7'
gem.metadata['rubygems_mfa_required'] = 'true'
end
41 changes: 21 additions & 20 deletions spec/omniauth/strategies/bigcommerce_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,79 @@
require 'spec_helper'

RSpec.describe OmniAuth::Strategies::BigCommerce do
subject { described_class.new({}) }

let(:store_hash) { 'abcdefg' }
let(:context) { "stores/#{store_hash}" }
let(:scope) { 'store_v2_products' }
let(:account_uuid) { 'foobar' }
let(:request) do
double('Request', params: { 'context' => context, 'scope' => scope, 'account_uuid' => account_uuid }, cookies: {},
env: {})
instance_double(Rack::Request, params: { 'context' => context, 'scope' => scope, 'account_uuid' => account_uuid },
cookies: {}, env: {})
end

before do
OmniAuth.config.test_mode = true
allow(subject).to receive(:request).and_return(request)
allow(subject).to receive(:script_name).and_return('')
allow(subject).to receive_messages(request: request, script_name: '')
end

after { OmniAuth.config.test_mode = false }
subject { OmniAuth::Strategies::BigCommerce.new({}) }

describe 'options' do
it 'should have correct name' do
it 'has correct name' do
expect(subject.options.name).to eq('bigcommerce')
end

describe 'client options' do
it 'should have correct site' do
it 'has correct site' do
# env variable set in spec_helper.rb
# TODO: change this once we have bigcommerceapp.com url
expect(subject.options.client_options.site).to eq('https://example.com')
end

it 'should have correct authorize url' do
expect(subject.options.client_options.authorize_url).to eq('/oauth2/authorize')
it 'has correct authorize url' do
expect(subject.options.client_options.authorize_url).to eq('oauth2/authorize')
end

it 'should have correct token url' do
expect(subject.options.client_options.token_url).to eq('/oauth2/token')
it 'has correct token url' do
expect(subject.options.client_options.token_url).to eq('oauth2/token')
end
end

describe 'OAuth2 settings' do
it 'should ignore state' do
expect(subject.options.provider_ignores_state).to eq true
it 'ignores state' do
expect(subject.options.provider_ignores_state).to be true
end
end
end

describe 'callback url' do
it 'should have the correct path' do
it 'has the correct path' do
expect(subject.callback_path).to eq('/auth/bigcommerce/callback')
end

context 'when callback url has a query string' do
let(:host) { 'https://example.com' }
let(:query_string) { 'foo=bar' }

before do
allow(subject).to receive(:full_host).and_return(host)
allow(subject).to receive(:query_string).and_return(query_string)
allow(subject).to receive_messages(full_host: host, script_name: '', query_string: query_string)
end

it 'query string should not be included in the callback url' do
it 'query string is not included in the callback url' do
expect(subject.callback_url).to eq("#{host}#{subject.callback_path}")
expect(subject.callback_url).to_not include(query_string)
expect(subject.callback_url).not_to include(query_string)
end
end
end

describe 'extra params for authorize and token exchange' do
it 'should set the context and scope parameters in the authorize request' do
it 'sets the context and scope parameters in the authorize request' do
expect(subject.authorize_params['context']).to eq(context)
expect(subject.authorize_params['scope']).to eq(scope)
end

it 'should set the context and scope parameters in the token request' do
it 'sets the context and scope parameters in the token request' do
expect(subject.token_params['context']).to eq(context)
expect(subject.token_params['scope']).to eq(scope)
expect(subject.token_params['account_uuid']).to eq(account_uuid)
Expand Down