devise_g5_authenticatable 1.0.1.rc.1 → 1.0.2.rc.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 45dc10e0dd1ef0be75f7ecdd379f5501a71baa5008fac90337b466fefdaf40b2
4
- data.tar.gz: 86e4f6bf860a0b547783ef30f417cc0c09d5bae31ce090ac3d6726a0dc626a75
3
+ metadata.gz: ad0eee25a4da3d85235fb21e4e0faae07e09debedf49e94fb7a02935936842c8
4
+ data.tar.gz: 98401d80d28e50845b8617362ee778ba0d62fb1c6f2b11840470d3ed808b7f5c
5
5
  SHA512:
6
- metadata.gz: b2a62a4b3973950c351ed21392625e0ee15c96e8ca40d9b6bc7b1281fd197507fde1c349eed58184ff5d06f1697f5e5494670db6231ef866fc1e42d7fde418ca
7
- data.tar.gz: d1c83f2985b31f9ef51019d64a42872c7ea772a66b100667e83aac1b8b66f985f9a4a9a6e325f5ad5b2440ca21e147fcf8bf28b435335de6c7357e35ad88db6b
6
+ metadata.gz: 2482e59fdd4ea7835a75f6c096d85d6fd51b4b207b7cb1cb856944da96ee687f7e49ace5b5d02c0beecb956c560e0ad2083768c3362ca57eb0aa0bbbc83db116
7
+ data.tar.gz: 3c7c5cea38df574c91065854aa7774c39d75cf581c3ab1635737e890a12095b90af08b371bba352f2c5ada5b71257ca0787409d1ca7580e62e50cd61b7de91a7
data/Gemfile CHANGED
@@ -16,6 +16,7 @@ group :test, :development do
16
16
  gem 'appraisal'
17
17
  gem 'pry-byebug'
18
18
  gem 'rspec-rails', '~> 3.6'
19
+ gem 'rb-readline'
19
20
  end
20
21
 
21
22
  group :test do
@@ -14,8 +14,11 @@ module DeviseG5Authenticatable
14
14
  end
15
15
 
16
16
  def create
17
- self.resource = resource_class.find_and_update_for_g5_oauth(auth_data)
18
- resource ? sign_in_resource : register_resource
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
@@ -127,7 +127,7 @@ module Devise
127
127
  private
128
128
 
129
129
  def without_auth_callback
130
- skip_callback :save, :before, :auth_user, raise: false
130
+ skip_callback :save, :before, :auth_user
131
131
  yield
132
132
  set_callback :save, :before, :auth_user
133
133
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeviseG5Authenticatable
4
- VERSION = '1.0.1.rc.1'
4
+ VERSION = '1.0.2.rc.1'
5
5
  end
@@ -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.1.rc.1
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: 2018-12-06 00:00:00.000000000 Z
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.8
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