omniauth-gorgias-oauth2 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e78d3a7049ce83a305edfd0227d169598628645d6d998975cf990cdd5a933712
4
+ data.tar.gz: 8acd4aa212fe634ed26a72e895e728c2517f4c90a51e5245c878d278b954261e
5
+ SHA512:
6
+ metadata.gz: 4a7b9f791182445720bae6b4f712480179cdf31b6ad4898b7b323d5c34e8b443ab22a5fcd467f84f347cbafeeccba233ce2c664f767dbebe413689e28cbb7c4f
7
+ data.tar.gz: c0abf63ab2f231351d9270d68eece2a17ffaac8e3bec4748684e2cfe9c6001b2262c48147d40c699124f245ac1f985d8a8a7e4323d53b5726b80d9677ab4f279
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in omniauth-gorgias-oauth2.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ omniauth-gorgias-oauth2 (0.1.0)
5
+ omniauth-oauth2 (~> 1.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.5.0)
11
+ faraday (1.10.0)
12
+ faraday-em_http (~> 1.0)
13
+ faraday-em_synchrony (~> 1.0)
14
+ faraday-excon (~> 1.1)
15
+ faraday-httpclient (~> 1.0)
16
+ faraday-multipart (~> 1.0)
17
+ faraday-net_http (~> 1.0)
18
+ faraday-net_http_persistent (~> 1.0)
19
+ faraday-patron (~> 1.0)
20
+ faraday-rack (~> 1.0)
21
+ faraday-retry (~> 1.0)
22
+ ruby2_keywords (>= 0.0.4)
23
+ faraday-em_http (1.0.0)
24
+ faraday-em_synchrony (1.0.0)
25
+ faraday-excon (1.1.0)
26
+ faraday-httpclient (1.0.1)
27
+ faraday-multipart (1.0.3)
28
+ multipart-post (>= 1.2, < 3)
29
+ faraday-net_http (1.0.1)
30
+ faraday-net_http_persistent (1.2.0)
31
+ faraday-patron (1.0.0)
32
+ faraday-rack (1.0.0)
33
+ faraday-retry (1.0.3)
34
+ hashie (5.0.0)
35
+ jwt (2.3.0)
36
+ multi_json (1.15.0)
37
+ multi_xml (0.6.0)
38
+ multipart-post (2.1.1)
39
+ oauth2 (1.4.9)
40
+ faraday (>= 0.17.3, < 3.0)
41
+ jwt (>= 1.0, < 3.0)
42
+ multi_json (~> 1.3)
43
+ multi_xml (~> 0.5)
44
+ rack (>= 1.2, < 3)
45
+ omniauth (2.1.0)
46
+ hashie (>= 3.4.6)
47
+ rack (>= 2.2.3)
48
+ rack-protection
49
+ omniauth-oauth2 (1.7.2)
50
+ oauth2 (~> 1.4)
51
+ omniauth (>= 1.9, < 3)
52
+ rack (2.2.3)
53
+ rack-protection (2.2.0)
54
+ rack
55
+ rake (10.5.0)
56
+ rspec (3.9.0)
57
+ rspec-core (~> 3.9.0)
58
+ rspec-expectations (~> 3.9.0)
59
+ rspec-mocks (~> 3.9.0)
60
+ rspec-core (3.9.3)
61
+ rspec-support (~> 3.9.3)
62
+ rspec-expectations (3.9.4)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.9.0)
65
+ rspec-mocks (3.9.1)
66
+ diff-lcs (>= 1.2.0, < 2.0)
67
+ rspec-support (~> 3.9.0)
68
+ rspec-support (3.9.4)
69
+ ruby2_keywords (0.0.5)
70
+
71
+ PLATFORMS
72
+ ruby
73
+
74
+ DEPENDENCIES
75
+ bundler (~> 1.17)
76
+ omniauth-gorgias-oauth2!
77
+ rake (~> 10.0)
78
+ rspec (~> 3.9, >= 3.9.0)
79
+
80
+ BUNDLED WITH
81
+ 1.17.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Fera Commerce Inc
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # OmniAuth::Gorgias::Oauth2
2
+ Gorgias OAuth2 Strategy for OmniAuth
3
+
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/omniauth/gorgias/oauth2`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-gorgias-oauth2'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install omniauth-gorgias-oauth2
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/azemoh/omniauth-gorgias-oauth2.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'spec'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Gorgias
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth/gorgias/version'
2
+ require 'omniauth/strategies/gorgias'
@@ -0,0 +1,60 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Gorgias < OmniAuth::Strategies::OAuth2
6
+ option :client_options, {
7
+ authorize_url: '/oauth/authorize',
8
+ token_url: '/oauth/token'
9
+ }
10
+
11
+ option :gorgias_domain, 'gorgias.com'
12
+
13
+ option :setup, (proc { |env|
14
+ strategy = env['omniauth.strategy']
15
+ site = "https://#{strategy.account}.#{strategy.options[:gorgias_domain]}"
16
+
17
+ strategy.options[:client_options][:site] = site
18
+ })
19
+
20
+ def request_phase
21
+ return fail!(:account_missing) unless account_present?
22
+
23
+ options[:scope] ||= 'openid'
24
+ options[:response_type] ||= 'code'
25
+
26
+ super
27
+ end
28
+
29
+ uid { account }
30
+
31
+ def authorize_params
32
+ nonce = SecureRandom.hex(16)
33
+ session['omniauth.nonce'] = nonce
34
+
35
+ super.merge(nonce: nonce)
36
+ end
37
+
38
+ def callback_url
39
+ full_host + script_name + callback_path + "?account=#{account}"
40
+ end
41
+
42
+ def token_params
43
+ super.merge(
44
+ headers: {
45
+ 'Authorization' => "Basic #{Base64.strict_encode64("#{options.client_id}:#{options.client_secret}")}"
46
+ },
47
+ redirect_uri: callback_url
48
+ )
49
+ end
50
+
51
+ def account
52
+ @account ||= request.params['account']
53
+ end
54
+
55
+ def account_present?
56
+ !!(account =~ /\A[a-z0-9]+\z/i)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/gorgias'
@@ -0,0 +1,24 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+ require 'omniauth/gorgias/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'omniauth-gorgias-oauth2'
6
+ spec.version = OmniAuth::Gorgias::VERSION
7
+ spec.authors = ['Joshua Azemoh', 'Fera Commerce Inc.']
8
+ spec.email = ['joshua@fera.ai', 'dev@feracommerce.com']
9
+
10
+ spec.summary = 'Gorgias OAuth2 strategy for OmniAuth'
11
+ spec.homepage = 'https://github.com/feracommerce/omniauth-gorgias-oauth2'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.5'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.17'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
23
+
24
+ end
@@ -0,0 +1,110 @@
1
+ require 'omniauth-gorgias-oauth2'
2
+
3
+ describe OmniAuth::Strategies::Gorgias do # rubocop:disable Metrics/BlockLength
4
+ let(:request) { double('Request', env: {}, params: { 'account' => 'test' }, cookies: {}) }
5
+ let(:client_id) { 'aBc123' }
6
+ let(:client_secret) { 'a1B2c3' }
7
+
8
+ subject do
9
+ args = [client_id, client_secret, {}].compact
10
+ OmniAuth::Strategies::Gorgias.new(nil, *args).tap do |strategy|
11
+ env = strategy.env || {}
12
+ env['omniauth.strategy'] = strategy
13
+
14
+ allow(strategy).to receive(:request) { request }
15
+ allow(strategy).to receive(:session) { {} }
16
+
17
+ strategy.options[:setup].call(env)
18
+ end
19
+ end
20
+
21
+ describe '::setup' do
22
+ it 'should set the site' do
23
+ expect(subject.options.client_options.site).to eq('https://test.gorgias.com')
24
+ end
25
+ end
26
+
27
+ describe '#client' do
28
+ it 'has correct gorgias site' do
29
+ expect(subject.client.site).to eq('https://test.gorgias.com')
30
+ end
31
+
32
+ it 'has correct authorize url' do
33
+ expect(subject.client.options[:authorize_url]).to eq('/oauth/authorize')
34
+ end
35
+
36
+ it 'has correct token url' do
37
+ expect(subject.client.options[:token_url]).to eq('/oauth/token')
38
+ end
39
+ end
40
+
41
+ describe '#callback_url' do
42
+ let(:base_url) { 'http://auth.myapp.com' }
43
+
44
+ it 'returns callback with account' do
45
+ allow(request).to receive(:scheme) { 'http' }
46
+ allow(request).to receive(:url) { "#{base_url}/path" }
47
+
48
+ allow(subject).to receive(:script_name) { '' } # to not depend from Rack env
49
+
50
+ expect(subject.callback_url).to eq("#{base_url}/auth/gorgias/callback?account=test")
51
+ end
52
+ end
53
+
54
+ describe '#authorize_params' do
55
+ it 'adds nonce' do
56
+ expect(subject.authorize_params).to be_a(Hash)
57
+ expect(subject.authorize_params[:nonce]).to be_a(String)
58
+ end
59
+ end
60
+
61
+ describe '#uid' do
62
+ it 'returns the account username' do
63
+ expect(subject.uid).to eq('test')
64
+ end
65
+ end
66
+
67
+ describe '#credentials' do
68
+ let(:access_token) { double('OAuth2::AccessToken') }
69
+
70
+ before :each do
71
+ allow(access_token).to receive(:token)
72
+ allow(access_token).to receive(:expires?)
73
+ allow(access_token).to receive(:expires_at)
74
+ allow(access_token).to receive(:refresh_token)
75
+
76
+ allow(subject).to receive(:access_token) { access_token }
77
+ end
78
+
79
+ it 'returns a Hash' do
80
+ expect(subject.credentials).to be_a(Hash)
81
+ end
82
+
83
+ it 'returns the token' do
84
+ allow(access_token).to receive(:token) { '123' }
85
+ expect(subject.credentials['token']).to eq('123')
86
+ end
87
+
88
+ it 'returns the expiry status' do
89
+ allow(access_token).to receive(:expires?) { true }
90
+ expect(subject.credentials['expires']).to eq(true)
91
+
92
+ allow(access_token).to receive(:expires?) { false }
93
+ expect(subject.credentials['expires']).to eq(false)
94
+ end
95
+ end
96
+
97
+ describe '#account_present?' do
98
+ it 'returns true if account query param is present' do
99
+ expect(subject.account_present?).to eq(true)
100
+ end
101
+
102
+ context 'when account is missing in the URL' do
103
+ let(:request) { double('Request', params: {}) }
104
+
105
+ it 'returns false' do
106
+ expect(subject.account_present?).to eq(false)
107
+ end
108
+ end
109
+ end
110
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-gorgias-oauth2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Azemoh
8
+ - Fera Commerce Inc.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2022-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.17'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.17'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.9'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 3.9.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '3.9'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.9.0
76
+ description:
77
+ email:
78
+ - joshua@fera.ai
79
+ - dev@feracommerce.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - lib/omniauth-gorgias-oauth2.rb
91
+ - lib/omniauth/gorgias.rb
92
+ - lib/omniauth/gorgias/version.rb
93
+ - lib/omniauth/strategies/gorgias.rb
94
+ - omniauth-gorgias-oauth2.gemspec
95
+ - spec/omniauth/strategies/gorgias_spec.rb
96
+ homepage: https://github.com/feracommerce/omniauth-gorgias-oauth2
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.7.6
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Gorgias OAuth2 strategy for OmniAuth
120
+ test_files: []