devise_g5_authenticatable 1.0.1.rc.1 → 1.0.2.rc.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/Gemfile +1 -0
- data/app/controllers/devise_g5_authenticatable/sessions_controller.rb +22 -2
- data/lib/devise_g5_authenticatable/models/g5_authenticatable.rb +1 -1
- data/lib/devise_g5_authenticatable/version.rb +1 -1
- data/spec/controllers/sessions_controller_spec.rb +53 -1
- data/spec/support/user_omniauth_methods.rb +7 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad0eee25a4da3d85235fb21e4e0faae07e09debedf49e94fb7a02935936842c8
|
4
|
+
data.tar.gz: 98401d80d28e50845b8617362ee778ba0d62fb1c6f2b11840470d3ed808b7f5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2482e59fdd4ea7835a75f6c096d85d6fd51b4b207b7cb1cb856944da96ee687f7e49ace5b5d02c0beecb956c560e0ad2083768c3362ca57eb0aa0bbbc83db116
|
7
|
+
data.tar.gz: 3c7c5cea38df574c91065854aa7774c39d75cf581c3ab1635737e890a12095b90af08b371bba352f2c5ada5b71257ca0787409d1ca7580e62e50cd61b7de91a7
|
data/Gemfile
CHANGED
@@ -14,8 +14,11 @@ module DeviseG5Authenticatable
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def create
|
17
|
-
|
18
|
-
|
17
|
+
if authorized?
|
18
|
+
sign_in_or_register
|
19
|
+
else
|
20
|
+
redirect_to(restricted_application_redirect_url)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
24
|
def destroy
|
@@ -26,6 +29,23 @@ module DeviseG5Authenticatable
|
|
26
29
|
|
27
30
|
protected
|
28
31
|
|
32
|
+
def authorized?
|
33
|
+
accessible_applications.map(&:url).include?(request.base_url) || accessible_applications.map(&:url).include?('global')
|
34
|
+
end
|
35
|
+
|
36
|
+
def accessible_applications
|
37
|
+
auth_data.extra.raw_info.accessible_applications
|
38
|
+
end
|
39
|
+
|
40
|
+
def restricted_application_redirect_url
|
41
|
+
auth_data.extra.raw_info.restricted_application_redirect_url
|
42
|
+
end
|
43
|
+
|
44
|
+
def sign_in_or_register
|
45
|
+
self.resource = resource_class.find_and_update_for_g5_oauth(auth_data)
|
46
|
+
resource ? sign_in_resource : register_resource
|
47
|
+
end
|
48
|
+
|
29
49
|
def auth_data
|
30
50
|
@auth_data ||= request.env['omniauth.auth']
|
31
51
|
session['omniauth.auth'] = @auth_data
|
@@ -41,7 +41,13 @@ RSpec.describe DeviseG5Authenticatable::SessionsController do
|
|
41
41
|
uid: '45',
|
42
42
|
info: { name: 'Foo Bar',
|
43
43
|
email: 'foo@bar.com' },
|
44
|
-
credentials: { token: 'abc123' }
|
44
|
+
credentials: { token: 'abc123' },
|
45
|
+
extra: {
|
46
|
+
raw_info: {
|
47
|
+
accessible_applications: [{ url: 'global' }],
|
48
|
+
restricted_application_redirect_url: 'https://imc.com'
|
49
|
+
}
|
50
|
+
}
|
45
51
|
)
|
46
52
|
end
|
47
53
|
before { request.env['omniauth.auth'] = auth_hash }
|
@@ -148,6 +154,52 @@ RSpec.describe DeviseG5Authenticatable::SessionsController do
|
|
148
154
|
end
|
149
155
|
end
|
150
156
|
end
|
157
|
+
|
158
|
+
context 'when user does not have access to application' do
|
159
|
+
let(:auth_hash) do
|
160
|
+
OmniAuth::AuthHash.new(
|
161
|
+
provider: 'g5',
|
162
|
+
uid: '45',
|
163
|
+
info: { name: 'Foo Bar',
|
164
|
+
email: 'foo@bar.com' },
|
165
|
+
credentials: { token: 'abc123' },
|
166
|
+
extra: {
|
167
|
+
raw_info: {
|
168
|
+
accessible_applications: [],
|
169
|
+
restricted_application_redirect_url: 'https://imc.com'
|
170
|
+
}
|
171
|
+
}
|
172
|
+
)
|
173
|
+
end
|
174
|
+
|
175
|
+
let(:model) do
|
176
|
+
stub_model(model_class,
|
177
|
+
provider: auth_hash.provider,
|
178
|
+
uid: auth_hash.uid,
|
179
|
+
email: auth_hash.email,
|
180
|
+
g5_access_token: auth_hash.credentials.token,
|
181
|
+
save!: true,
|
182
|
+
update_g5_credentials: true,
|
183
|
+
email_changed?: false)
|
184
|
+
end
|
185
|
+
|
186
|
+
before do
|
187
|
+
allow(model_class).to receive(:find_and_update_for_g5_oauth)
|
188
|
+
.and_return(model)
|
189
|
+
end
|
190
|
+
|
191
|
+
let(:model_class) { User }
|
192
|
+
let(:scope) { :user }
|
193
|
+
|
194
|
+
it 'should redirect the user to the restricted_application_redirect_url' do
|
195
|
+
create_session
|
196
|
+
expect(subject).to redirect_to(auth_hash.extra.raw_info.restricted_application_redirect_url)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should not sign in a user' do
|
200
|
+
expect { create_session }.to_not change { controller.current_user }
|
201
|
+
end
|
202
|
+
end
|
151
203
|
end
|
152
204
|
|
153
205
|
describe '#destroy' do
|
@@ -6,7 +6,13 @@ module UserOmniauthMethods
|
|
6
6
|
uid: user.uid,
|
7
7
|
provider: 'g5',
|
8
8
|
info: { email: user.email },
|
9
|
-
credentials: { token: user.g5_access_token }
|
9
|
+
credentials: { token: user.g5_access_token },
|
10
|
+
extra: {
|
11
|
+
raw_info: {
|
12
|
+
accessible_applications: [{ url: 'global' }],
|
13
|
+
restricted_application_redirect_url: 'https://imc.com'
|
14
|
+
}
|
15
|
+
}
|
10
16
|
}.merge(options))
|
11
17
|
end
|
12
18
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_g5_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2.rc.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maeve Revels
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devise
|
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: 1.3.1
|
207
207
|
requirements: []
|
208
208
|
rubyforge_project:
|
209
|
-
rubygems_version: 2.7.
|
209
|
+
rubygems_version: 2.7.6
|
210
210
|
signing_key:
|
211
211
|
specification_version: 4
|
212
212
|
summary: Devise extension for the G5 Auth service
|