omniauth-scalus-oauth2 1.0.0 → 1.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 +4 -4
- data/README.md +1 -1
- data/example/config.ru +3 -3
- data/lib/omniauth/scalus/version.rb +1 -1
- data/lib/omniauth/strategies/scalus.rb +3 -3
- data/spec/omniauth/strategies/scalus_spec.rb +11 -11
- data/test/integration_test.rb +33 -33
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a038498007dcbc8171616d47cf494e0e3c0142f
|
4
|
+
data.tar.gz: e38a4e540c91f3c2f53b36d1e71dba5eea9795de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a8aa80ff17bd0706b4e11fa241b5a839ebbd3551b995bdd7aa20fa11f466235e11811b40562f3056e8edd0c002b5ad4609640744953ae810bfe24f0329b4a60
|
7
|
+
data.tar.gz: 5a7cdc43446f91e7649c2d83aff2f5a8fc4ed539c202845227c9c7d12a580dfef78b73795b768f893234b96babf29382f75f7eb4be19c960756fddbd8a9b9ff3
|
data/README.md
CHANGED
@@ -45,7 +45,7 @@ Here's an example *Authentication Hash* available in `request.env['omniauth.auth
|
|
45
45
|
```ruby
|
46
46
|
{
|
47
47
|
:provider => 'scalus',
|
48
|
-
:uid => 'example.
|
48
|
+
:uid => 'example.scalus.com',
|
49
49
|
:credentials => {
|
50
50
|
:token => 'afasd923kjh0934kf', # OAuth 2.0 access_token, which you store and use to authenticate API requests
|
51
51
|
}
|
data/example/config.ru
CHANGED
@@ -19,8 +19,8 @@ class App < Sinatra::Base
|
|
19
19
|
</head>
|
20
20
|
<body>
|
21
21
|
<form action="/auth/scalus" method="get">
|
22
|
-
<label for="
|
23
|
-
<input type="text" name="
|
22
|
+
<label for="organization">Enter your Scalus Subdomain:</label>
|
23
|
+
<input type="text" name="organization" placeholder="your-scalus-url.scalus.com">
|
24
24
|
<button type="submit">Log In</button>
|
25
25
|
</form>
|
26
26
|
</body>
|
@@ -36,7 +36,7 @@ class App < Sinatra::Base
|
|
36
36
|
</head>
|
37
37
|
<body>
|
38
38
|
<h3>Authorized</h3>
|
39
|
-
<p>
|
39
|
+
<p>Organization: #{request.env['omniauth.auth'].uid}</p>
|
40
40
|
<p>Token: #{request.env['omniauth.auth']['credentials']['token']}</p>
|
41
41
|
</body>
|
42
42
|
</html>
|
@@ -15,17 +15,17 @@ module OmniAuth
|
|
15
15
|
}
|
16
16
|
|
17
17
|
option :callback_url
|
18
|
-
option :
|
18
|
+
option :scalus_domain, 'scalus.com'
|
19
19
|
|
20
20
|
option :setup, proc { |env|
|
21
21
|
request = Rack::Request.new(env)
|
22
|
-
env['omniauth.strategy'].options[:client_options][:site] = "https://#{request.GET['
|
22
|
+
env['omniauth.strategy'].options[:client_options][:site] = "https://#{request.GET['organization']}"
|
23
23
|
}
|
24
24
|
|
25
25
|
uid { URI.parse(options[:client_options][:site]).host }
|
26
26
|
|
27
27
|
def valid_site?
|
28
|
-
!!(/\A(https|http)\:\/\/[a-zA-Z0-9][a-zA-Z0-9\-]*\.#{Regexp.quote(options[:
|
28
|
+
!!(/\A(https|http)\:\/\/[a-zA-Z0-9][a-zA-Z0-9\-]*\.#{Regexp.quote(options[:scalus_domain])}[\/]?\z/ =~ options[:client_options][:site])
|
29
29
|
end
|
30
30
|
|
31
31
|
def valid_signature?
|
@@ -11,7 +11,7 @@ describe OmniAuth::Strategies::Scalus do
|
|
11
11
|
|
12
12
|
@client_id = '123'
|
13
13
|
@client_secret = '53cr3tz'
|
14
|
-
@options = {:client_options => {:site => 'https://example.
|
14
|
+
@options = {:client_options => {:site => 'https://example.scalus.com'}}
|
15
15
|
end
|
16
16
|
|
17
17
|
subject do
|
@@ -38,7 +38,7 @@ describe OmniAuth::Strategies::Scalus do
|
|
38
38
|
|
39
39
|
describe '#client' do
|
40
40
|
it 'has correct scalus site' do
|
41
|
-
subject.client.site.should eq('https://example.
|
41
|
+
subject.client.site.should eq('https://example.scalus.com')
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'has correct authorize url' do
|
@@ -80,8 +80,8 @@ describe OmniAuth::Strategies::Scalus do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe '#uid' do
|
83
|
-
it 'returns the
|
84
|
-
subject.uid.should eq('example.
|
83
|
+
it 'returns the organization' do
|
84
|
+
subject.uid.should eq('example.scalus.com')
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -115,23 +115,23 @@ describe OmniAuth::Strategies::Scalus do
|
|
115
115
|
end
|
116
116
|
|
117
117
|
describe '#valid_site?' do
|
118
|
-
it 'returns true if the site contains .
|
119
|
-
@options = {:client_options => {:site => 'http://foo.
|
118
|
+
it 'returns true if the site contains .scalus.com' do
|
119
|
+
@options = {:client_options => {:site => 'http://foo.scalus.com/'}}
|
120
120
|
subject.valid_site?.should eq(true)
|
121
121
|
end
|
122
122
|
|
123
|
-
it 'returns false if the site does not contain .
|
123
|
+
it 'returns false if the site does not contain .scalus.com' do
|
124
124
|
@options = {:client_options => {:site => 'http://foo.example.com/'}}
|
125
125
|
subject.valid_site?.should eq(false)
|
126
126
|
end
|
127
127
|
|
128
|
-
it 'uses configurable option for
|
129
|
-
@options = {:client_options => {:site => 'http://foo.example.com/'}, :
|
128
|
+
it 'uses configurable option for scalus_domain' do
|
129
|
+
@options = {:client_options => {:site => 'http://foo.example.com/'}, :scalus_domain => 'example.com'}
|
130
130
|
subject.valid_site?.should eq(true)
|
131
131
|
end
|
132
132
|
|
133
|
-
it 'allows custom port for
|
134
|
-
@options = {:client_options => {:site => 'http://foo.example.com:3456/'}, :
|
133
|
+
it 'allows custom port for scalus_domain' do
|
134
|
+
@options = {:client_options => {:site => 'http://foo.example.com:3456/'}, :scalus_domain => 'example.com:3456'}
|
135
135
|
subject.valid_site?.should eq(true)
|
136
136
|
end
|
137
137
|
end
|
data/test/integration_test.rb
CHANGED
@@ -11,9 +11,9 @@ class IntegrationTest < Minitest::Test
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_authorize
|
14
|
-
response = authorize('snowdevil.
|
14
|
+
response = authorize('snowdevil.scalus.com')
|
15
15
|
assert_equal 302, response.status
|
16
|
-
assert_match /\A#{Regexp.quote("https://snowdevil.
|
16
|
+
assert_match /\A#{Regexp.quote("https://snowdevil.scalus.com/admin/oauth/authorize?")}/, response.location
|
17
17
|
redirect_params = Rack::Utils.parse_query(URI(response.location).query)
|
18
18
|
assert_equal "123", redirect_params['client_id']
|
19
19
|
assert_equal "https://app.example.com/auth/scalus/callback", redirect_params['redirect_uri']
|
@@ -23,27 +23,27 @@ class IntegrationTest < Minitest::Test
|
|
23
23
|
def test_authorize_overrides_site_with_https_scheme
|
24
24
|
build_app setup: lambda { |env|
|
25
25
|
params = Rack::Utils.parse_query(env['QUERY_STRING'])
|
26
|
-
env['omniauth.strategy'].options[:client_options][:site] = "http://#{params['
|
26
|
+
env['omniauth.strategy'].options[:client_options][:site] = "http://#{params['organization']}"
|
27
27
|
}
|
28
28
|
|
29
|
-
response = authorize('snowdevil.
|
30
|
-
assert_match /\A#{Regexp.quote("https://snowdevil.
|
29
|
+
response = authorize('snowdevil.scalus.com')
|
30
|
+
assert_match /\A#{Regexp.quote("https://snowdevil.scalus.com/admin/oauth/authorize?")}/, response.location
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_site_validation
|
34
34
|
code = SecureRandom.hex(16)
|
35
35
|
|
36
36
|
[
|
37
|
-
'foo.example.com', #
|
38
|
-
'http://snowdevil.
|
39
|
-
'snowdevil.
|
40
|
-
'user@snowdevil.
|
41
|
-
'snowdevil.
|
42
|
-
].each do |
|
43
|
-
response = authorize(
|
37
|
+
'foo.example.com', # organization doesn't end with .scalus.com
|
38
|
+
'http://snowdevil.scalus.com', # organization contains protocol
|
39
|
+
'snowdevil.scalus.com/path', # organization contains path
|
40
|
+
'user@snowdevil.scalus.com', # organization contains user
|
41
|
+
'snowdevil.scalus.com:22', # organization contains port
|
42
|
+
].each do |organization, valid|
|
43
|
+
response = authorize(organization)
|
44
44
|
assert_auth_failure(response, 'invalid_site')
|
45
45
|
|
46
|
-
response = callback(sign_params(
|
46
|
+
response = callback(sign_params(organization: organization, code: code))
|
47
47
|
assert_auth_failure(response, 'invalid_site')
|
48
48
|
end
|
49
49
|
end
|
@@ -53,7 +53,7 @@ class IntegrationTest < Minitest::Test
|
|
53
53
|
code = SecureRandom.hex(16)
|
54
54
|
expect_access_token_request(access_token)
|
55
55
|
|
56
|
-
response = callback(sign_params(
|
56
|
+
response = callback(sign_params(organization: 'snowdevil.scalus.com', code: code, state: opts["rack.session"]["omniauth.state"]))
|
57
57
|
|
58
58
|
assert_callback_success(response, access_token, code)
|
59
59
|
end
|
@@ -63,7 +63,7 @@ class IntegrationTest < Minitest::Test
|
|
63
63
|
code = SecureRandom.hex(16)
|
64
64
|
expect_access_token_request(access_token)
|
65
65
|
|
66
|
-
response = callback(sign_params(
|
66
|
+
response = callback(sign_params(organization: 'snowdevil.scalus.com', code: code, state: opts["rack.session"]["omniauth.state"]).merge(signature: 'ignored'))
|
67
67
|
|
68
68
|
assert_callback_success(response, access_token, code)
|
69
69
|
end
|
@@ -71,13 +71,13 @@ class IntegrationTest < Minitest::Test
|
|
71
71
|
def test_callback_custom_params
|
72
72
|
access_token = SecureRandom.hex(16)
|
73
73
|
code = SecureRandom.hex(16)
|
74
|
-
FakeWeb.register_uri(:post, "https://snowdevil.
|
74
|
+
FakeWeb.register_uri(:post, "https://snowdevil.scalus.com/admin/oauth/access_token",
|
75
75
|
body: JSON.dump(access_token: access_token),
|
76
76
|
content_type: 'application/json')
|
77
77
|
|
78
78
|
now = Time.now.to_i
|
79
|
-
params = {
|
80
|
-
encoded_params = "code=#{code}&next=/products?page=2%26q=red%2520shirt&
|
79
|
+
params = { organization: 'snowdevil.scalus.com', code: code, timestamp: now, next: '/products?page=2&q=red%20shirt', state: opts["rack.session"]["omniauth.state"] }
|
80
|
+
encoded_params = "code=#{code}&next=/products?page=2%26q=red%2520shirt&organization=snowdevil.scalus.com&state=#{opts["rack.session"]["omniauth.state"]}×tamp=#{now}"
|
81
81
|
params[:hmac] = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA256.new, @secret, encoded_params)
|
82
82
|
|
83
83
|
response = callback(params)
|
@@ -87,14 +87,14 @@ class IntegrationTest < Minitest::Test
|
|
87
87
|
|
88
88
|
def test_callback_rejects_invalid_hmac
|
89
89
|
@secret = 'wrong_secret'
|
90
|
-
response = callback(sign_params(
|
90
|
+
response = callback(sign_params(organization: 'snowdevil.scalus.com', code: SecureRandom.hex(16)))
|
91
91
|
|
92
92
|
assert_auth_failure(response, 'invalid_signature')
|
93
93
|
end
|
94
94
|
|
95
95
|
def test_callback_rejects_old_timestamps
|
96
96
|
expired_timestamp = Time.now.to_i - OmniAuth::Strategies::Scalus::CODE_EXPIRES_AFTER - 1
|
97
|
-
response = callback(sign_params(
|
97
|
+
response = callback(sign_params(organization: 'snowdevil.scalus.com', code: SecureRandom.hex(16), timestamp: expired_timestamp))
|
98
98
|
|
99
99
|
assert_auth_failure(response, 'invalid_signature')
|
100
100
|
end
|
@@ -102,14 +102,14 @@ class IntegrationTest < Minitest::Test
|
|
102
102
|
def test_callback_rejects_missing_hmac
|
103
103
|
code = SecureRandom.hex(16)
|
104
104
|
|
105
|
-
response = callback(
|
105
|
+
response = callback(organization: 'snowdevil.scalus.com', code: code, timestamp: Time.now.to_i)
|
106
106
|
|
107
107
|
assert_auth_failure(response, 'invalid_signature')
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_callback_rejects_body_params
|
111
111
|
code = SecureRandom.hex(16)
|
112
|
-
params = sign_params(
|
112
|
+
params = sign_params(organization: 'snowdevil.scalus.com', code: code)
|
113
113
|
body = Rack::Utils.build_nested_query(unsigned: 'value')
|
114
114
|
|
115
115
|
response = request.get("https://app.example.com/auth/scalus/callback?#{Rack::Utils.build_query(params)}",
|
@@ -122,16 +122,16 @@ class IntegrationTest < Minitest::Test
|
|
122
122
|
def test_provider_options
|
123
123
|
build_app scope: 'read_products,read_orders,write_content',
|
124
124
|
callback_path: '/admin/auth/legacy/callback',
|
125
|
-
|
125
|
+
scalus_domain: 'scalus.dev:3000',
|
126
126
|
setup: lambda { |env|
|
127
|
-
|
128
|
-
|
129
|
-
env['omniauth.strategy'].options[:client_options][:site] = "https://#{
|
127
|
+
organization = Rack::Request.new(env).GET['organization']
|
128
|
+
organization += ".scalus.dev:3000" unless organization.include?(".")
|
129
|
+
env['omniauth.strategy'].options[:client_options][:site] = "https://#{organization}"
|
130
130
|
}
|
131
131
|
|
132
132
|
response = authorize('snowdevil')
|
133
133
|
assert_equal 302, response.status
|
134
|
-
assert_match /\A#{Regexp.quote("https://snowdevil.
|
134
|
+
assert_match /\A#{Regexp.quote("https://snowdevil.scalus.dev:3000/admin/oauth/authorize?")}/, response.location
|
135
135
|
redirect_params = Rack::Utils.parse_query(URI(response.location).query)
|
136
136
|
assert_equal 'read_products,read_orders,write_content', redirect_params['scope']
|
137
137
|
assert_equal 'https://app.example.com/admin/auth/legacy/callback', redirect_params['redirect_uri']
|
@@ -139,11 +139,11 @@ class IntegrationTest < Minitest::Test
|
|
139
139
|
def test_callback_with_invalid_state_fails
|
140
140
|
access_token = SecureRandom.hex(16)
|
141
141
|
code = SecureRandom.hex(16)
|
142
|
-
FakeWeb.register_uri(:post, "https://snowdevil.
|
142
|
+
FakeWeb.register_uri(:post, "https://snowdevil.scalus.com/admin/oauth/access_token",
|
143
143
|
body: JSON.dump(access_token: access_token),
|
144
144
|
content_type: 'application/json')
|
145
145
|
|
146
|
-
response = callback(sign_params(
|
146
|
+
response = callback(sign_params(organization: 'snowdevil.scalus.com', code: code, state: 'invalid'))
|
147
147
|
|
148
148
|
assert_equal 302, response.status
|
149
149
|
assert_equal '/auth/failure?message=csrf_detected&strategy=scalus', response.location
|
@@ -161,7 +161,7 @@ class IntegrationTest < Minitest::Test
|
|
161
161
|
end
|
162
162
|
|
163
163
|
def expect_access_token_request(access_token)
|
164
|
-
FakeWeb.register_uri(:post, "https://snowdevil.
|
164
|
+
FakeWeb.register_uri(:post, "https://snowdevil.scalus.com/admin/oauth/access_token",
|
165
165
|
body: JSON.dump(access_token: access_token),
|
166
166
|
content_type: 'application/json')
|
167
167
|
end
|
@@ -172,7 +172,7 @@ class IntegrationTest < Minitest::Test
|
|
172
172
|
assert_equal token_request_params['client_secret'], @secret
|
173
173
|
assert_equal token_request_params['code'], code
|
174
174
|
|
175
|
-
assert_equal 'snowdevil.
|
175
|
+
assert_equal 'snowdevil.scalus.com', @omniauth_result.uid
|
176
176
|
assert_equal access_token, @omniauth_result.credentials.token
|
177
177
|
assert_equal false, @omniauth_result.credentials.expires
|
178
178
|
|
@@ -200,8 +200,8 @@ class IntegrationTest < Minitest::Test
|
|
200
200
|
@app = Rack::Session::Cookie.new(app, secret: SecureRandom.hex(64))
|
201
201
|
end
|
202
202
|
|
203
|
-
def authorize(
|
204
|
-
request.get("https://app.example.com/auth/scalus?
|
203
|
+
def authorize(organization)
|
204
|
+
request.get("https://app.example.com/auth/scalus?organization=#{CGI.escape(organization)}", opts)
|
205
205
|
end
|
206
206
|
|
207
207
|
def callback(params)
|