omniauth-square-oauth2 0.0.1
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 +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +71 -0
- data/LICENSE +21 -0
- data/README.md +27 -0
- data/Rakefile +7 -0
- data/coverage/.last_run.json +5 -0
- data/coverage/.resultset.json +77 -0
- data/coverage/.resultset.json.lock +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.12.3/application.css +1 -0
- data/coverage/assets/0.12.3/application.js +7 -0
- data/coverage/assets/0.12.3/colorbox/border.png +0 -0
- data/coverage/assets/0.12.3/colorbox/controls.png +0 -0
- data/coverage/assets/0.12.3/colorbox/loading.gif +0 -0
- data/coverage/assets/0.12.3/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.12.3/favicon_green.png +0 -0
- data/coverage/assets/0.12.3/favicon_red.png +0 -0
- data/coverage/assets/0.12.3/favicon_yellow.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.12.3/loading.gif +0 -0
- data/coverage/assets/0.12.3/magnify.png +0 -0
- data/coverage/index.html +859 -0
- data/lib/omniauth-square.rb +2 -0
- data/lib/omniauth-square/version.rb +5 -0
- data/lib/omniauth/strategies/square.rb +60 -0
- data/omniauth-square-oauth2.gemspec +26 -0
- data/spec/omniauth/strategies/square_spec.rb +107 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/shared_examples.rb +23 -0
- metadata +181 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'omniauth/strategies/oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class Square < OmniAuth::Strategies::OAuth2
|
6
|
+
option :client_options, {
|
7
|
+
:site => 'https://squareup.com/',
|
8
|
+
:connect_site => 'https://connect.squareup.com',
|
9
|
+
:authorize_url => '/oauth2/authorize',
|
10
|
+
:token_url => '/oauth2/token'
|
11
|
+
}
|
12
|
+
|
13
|
+
uid { raw_info["merchant"][0]["id"] }
|
14
|
+
|
15
|
+
info do
|
16
|
+
prune!(
|
17
|
+
:name => raw_info["merchant"][0]["business_name"],
|
18
|
+
:country => raw_info["merchant"][0]["country"]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
extra do
|
23
|
+
{ :raw_info => raw_info }
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_access_token
|
27
|
+
connect_client = client.dup
|
28
|
+
connect_client.site = options.client_options.connect_site
|
29
|
+
auth_params = {
|
30
|
+
:redirect_uri => callback_url,
|
31
|
+
:client_id => options.client_id,
|
32
|
+
:client_secret => options.client_secret,
|
33
|
+
:grant_type => "authorization_code"
|
34
|
+
}.merge(token_params.to_hash(:symbolize_keys => true))
|
35
|
+
connect_client.auth_code.get_token(
|
36
|
+
request.params["code"],
|
37
|
+
auth_params.merge(
|
38
|
+
token_params.to_hash(:symbolize_keys => true)
|
39
|
+
),
|
40
|
+
deep_symbolize(options.auth_token_params)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def raw_info
|
47
|
+
@raw_info ||= access_token.get('/v2/merchants').parsed
|
48
|
+
end
|
49
|
+
|
50
|
+
def prune!(hash)
|
51
|
+
hash.delete_if do |_, value|
|
52
|
+
prune!(value) if value.is_a?(Hash)
|
53
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
OmniAuth.config.add_camelization 'square', 'Square'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-square/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-square-oauth2"
|
7
|
+
s.version = Omniauth::Square::VERSION
|
8
|
+
s.authors = ["Nick Robinson"]
|
9
|
+
s.email = ["nrobinson13+github@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/nickrobinson/omniauth-square-oauth2"
|
11
|
+
s.summary = %q{Square OAuth strategy for OmniAuth}
|
12
|
+
s.description = %q{Square OAuth strategy for OmniAuth}
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_runtime_dependency 'omniauth-oauth2', '>= 1.1.1', '< 1.3.0'
|
21
|
+
s.add_development_dependency 'rspec', '~> 2.7'
|
22
|
+
s.add_development_dependency 'rack-test'
|
23
|
+
s.add_development_dependency "rake", "~> 10.0"
|
24
|
+
s.add_development_dependency 'simplecov'
|
25
|
+
s.add_development_dependency 'webmock'
|
26
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Strategies::Square do
|
4
|
+
before :each do
|
5
|
+
@request = double('Request', :scheme => '', :url => '')
|
6
|
+
@request.stub(:params) { {} }
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
OmniAuth::Strategies::Square.new(nil, @options || {}).tap do |strategy|
|
11
|
+
strategy.stub(:request) { @request }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#client' do
|
16
|
+
it 'has correct Square site' do
|
17
|
+
subject.client.site.should eq('https://squareup.com/')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has correct authorize url' do
|
21
|
+
subject.client.options[:authorize_url].should eq('/oauth2/authorize')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has correct token url' do
|
25
|
+
subject.client.options[:token_url].should eq('/oauth2/token')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#info' do
|
30
|
+
before :each do
|
31
|
+
@raw_info = {
|
32
|
+
"merchant" => [{
|
33
|
+
"id" => "JGHJ0343",
|
34
|
+
"business_name" => "Foobar Sports",
|
35
|
+
"country" => "US",
|
36
|
+
"language_code" => "en-US",
|
37
|
+
"currency" => "USD",
|
38
|
+
"status" => "ACTIVE",
|
39
|
+
"main_location_id" => "DDM555V5KQPNS"
|
40
|
+
}]
|
41
|
+
}
|
42
|
+
|
43
|
+
subject.stub(:raw_info) { @raw_info }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when data is present in raw info' do
|
47
|
+
it 'returns the name' do
|
48
|
+
subject.info[:name].should eq('Foobar Sports')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'returns raw info' do
|
52
|
+
subject.extra[:raw_info]['merchant'][0]['business_name'].should eq("Foobar Sports")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#credentials' do
|
58
|
+
before :each do
|
59
|
+
@access_token = double('OAuth2::AccessToken')
|
60
|
+
@access_token.stub(:token)
|
61
|
+
@access_token.stub(:expires?)
|
62
|
+
@access_token.stub(:expires_at)
|
63
|
+
@access_token.stub(:refresh_token)
|
64
|
+
subject.stub(:access_token) { @access_token }
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'returns a Hash' do
|
68
|
+
subject.credentials.should be_a(Hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns the token' do
|
72
|
+
@access_token.stub(:token) { '123' }
|
73
|
+
subject.credentials['token'].should eq('123')
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the expiry status' do
|
77
|
+
@access_token.stub(:expires?) { true }
|
78
|
+
subject.credentials['expires'].should eq(true)
|
79
|
+
|
80
|
+
@access_token.stub(:expires?) { false }
|
81
|
+
subject.credentials['expires'].should eq(false)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the refresh token and expiry time when expiring' do
|
85
|
+
ten_mins_from_now = (Time.now + 360).to_i
|
86
|
+
@access_token.stub(:expires?) { true }
|
87
|
+
@access_token.stub(:refresh_token) { '321' }
|
88
|
+
@access_token.stub(:expires_at) { ten_mins_from_now }
|
89
|
+
subject.credentials['refresh_token'].should eq('321')
|
90
|
+
subject.credentials['expires_at'].should eq(ten_mins_from_now)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'does not return the refresh token when it is nil and expiring' do
|
94
|
+
@access_token.stub(:expires?) { true }
|
95
|
+
@access_token.stub(:refresh_token) { nil }
|
96
|
+
subject.credentials['refresh_token'].should be_nil
|
97
|
+
subject.credentials.should_not have_key('refresh_token')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'does not return the refresh token when not expiring' do
|
101
|
+
@access_token.stub(:expires?) { false }
|
102
|
+
@access_token.stub(:refresh_token) { 'XXX' }
|
103
|
+
subject.credentials['refresh_token'].should be_nil
|
104
|
+
subject.credentials.should_not have_key('refresh_token')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
require 'rspec'
|
4
|
+
require 'rack/test'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'omniauth'
|
7
|
+
require 'omniauth-square'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.include WebMock::API
|
11
|
+
config.include Rack::Test::Methods
|
12
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# NOTE it would be useful if this lived in omniauth-oauth2 eventually
|
2
|
+
shared_examples 'an oauth2 strategy' do
|
3
|
+
describe '#client' do
|
4
|
+
it 'should be initialized with symbolized client_options' do
|
5
|
+
@options = { :client_options => { 'authorize_url' => 'https://example.com' } }
|
6
|
+
subject.client.options[:authorize_url].should == 'https://example.com'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#token_params' do
|
11
|
+
it 'should include any authorize params passed in the :authorize_params option' do
|
12
|
+
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
13
|
+
subject.token_params['foo'].should eq('bar')
|
14
|
+
subject.token_params['baz'].should eq('zip')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should include top-level options that are marked as :authorize_options' do
|
18
|
+
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
19
|
+
subject.token_params['scope'].should eq('bar')
|
20
|
+
subject.token_params['foo'].should eq('baz')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-square-oauth2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Robinson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth-oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.1
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.3.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.1.1
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.3.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rspec
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.7'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rack-test
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: simplecov
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: webmock
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
description: Square OAuth strategy for OmniAuth
|
104
|
+
email:
|
105
|
+
- nrobinson13+github@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- coverage/.last_run.json
|
116
|
+
- coverage/.resultset.json
|
117
|
+
- coverage/.resultset.json.lock
|
118
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png
|
119
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png
|
120
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png
|
121
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc.png
|
122
|
+
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_desc_disabled.png
|
123
|
+
- coverage/assets/0.12.3/application.css
|
124
|
+
- coverage/assets/0.12.3/application.js
|
125
|
+
- coverage/assets/0.12.3/colorbox/border.png
|
126
|
+
- coverage/assets/0.12.3/colorbox/controls.png
|
127
|
+
- coverage/assets/0.12.3/colorbox/loading.gif
|
128
|
+
- coverage/assets/0.12.3/colorbox/loading_background.png
|
129
|
+
- coverage/assets/0.12.3/favicon_green.png
|
130
|
+
- coverage/assets/0.12.3/favicon_red.png
|
131
|
+
- coverage/assets/0.12.3/favicon_yellow.png
|
132
|
+
- coverage/assets/0.12.3/images/ui-bg_flat_0_aaaaaa_40x100.png
|
133
|
+
- coverage/assets/0.12.3/images/ui-bg_flat_75_ffffff_40x100.png
|
134
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_55_fbf9ee_1x400.png
|
135
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_65_ffffff_1x400.png
|
136
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_75_dadada_1x400.png
|
137
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_75_e6e6e6_1x400.png
|
138
|
+
- coverage/assets/0.12.3/images/ui-bg_glass_95_fef1ec_1x400.png
|
139
|
+
- coverage/assets/0.12.3/images/ui-bg_highlight-soft_75_cccccc_1x100.png
|
140
|
+
- coverage/assets/0.12.3/images/ui-icons_222222_256x240.png
|
141
|
+
- coverage/assets/0.12.3/images/ui-icons_2e83ff_256x240.png
|
142
|
+
- coverage/assets/0.12.3/images/ui-icons_454545_256x240.png
|
143
|
+
- coverage/assets/0.12.3/images/ui-icons_888888_256x240.png
|
144
|
+
- coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png
|
145
|
+
- coverage/assets/0.12.3/loading.gif
|
146
|
+
- coverage/assets/0.12.3/magnify.png
|
147
|
+
- coverage/index.html
|
148
|
+
- lib/omniauth-square.rb
|
149
|
+
- lib/omniauth-square/version.rb
|
150
|
+
- lib/omniauth/strategies/square.rb
|
151
|
+
- omniauth-square-oauth2.gemspec
|
152
|
+
- spec/omniauth/strategies/square_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/shared_examples.rb
|
155
|
+
homepage: https://github.com/nickrobinson/omniauth-square-oauth2
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubygems_version: 3.1.2
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: Square OAuth strategy for OmniAuth
|
178
|
+
test_files:
|
179
|
+
- spec/omniauth/strategies/square_spec.rb
|
180
|
+
- spec/spec_helper.rb
|
181
|
+
- spec/support/shared_examples.rb
|