omniauth-identity 3.0.5 → 3.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e486fff1d58be9ad944402aa2952bfceca493c6e78f1ba8c1e29cf6142543b01
4
- data.tar.gz: a4be9557b902ff9dfe779baea964477aaf127519f8e389b82aa3cd83af3041da
3
+ metadata.gz: 469e5989686f13b8e924e7efc5cfbd2f205a13d45da6410f454f2d0b14e884ea
4
+ data.tar.gz: 38424bbbc877d8d18aa4a35916697c59b31379809e05e5ff620de0089f53759c
5
5
  SHA512:
6
- metadata.gz: 3f4d5a82e3ee782716992b1183cac66e6a29cee8037a8491a56bb8dd832ee9f22946eee7900d9e1d8d20d9bc5dcce3336652f25f606f027e87d79be6a9a00c6d
7
- data.tar.gz: f2de6f02475fe119947bd6ba2f66e9585664b522833180e5327fcda8aa3b92c8fcb95d3bfb6baf45724851c1dd6c2a8144fe473f70715c6399b8025d73b195b2
6
+ metadata.gz: 1458cc73c99ca0bb267f9730d5e64daa8d6b7460720dd5790d443292cc8e938434190fcaf55195e5f039ffd50286018045ac2e0ed8c9a8e83eb5cae5878dcb62
7
+ data.tar.gz: 439a1bd2702a7d5a729be16ad65fdd079a6a867f9ffa26c823b63d675dcaf2127311097b4f51a8c42425c33aba1d490dc46abf92d4bdab6c0185e191952d244c
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAuth
4
4
  module Identity
5
- VERSION = '3.0.5'
5
+ VERSION = '3.0.6'
6
6
  end
7
7
  end
@@ -20,6 +20,11 @@ module OmniAuth
20
20
  option :on_registration, nil # See #registration_phase
21
21
  option :on_failed_registration, nil # See #registration_phase
22
22
  option :locate_conditions, ->(req) { { model.auth_key => req['auth_key'] } }
23
+ option :create_identity_link_text, 'Create an Identity'
24
+ option :registration_failure_message, 'One or more fields were invalid'
25
+ option :validation_failure_message, 'Validation failed'
26
+ option :title, 'Identity Verification' # Title for Login Form
27
+ option :registration_form_title, 'Register Identity' # Title for Registration Form
23
28
 
24
29
  def request_phase
25
30
  if options[:on_login]
@@ -71,14 +76,14 @@ module OmniAuth
71
76
  if model.respond_to?(:column_names) && model.column_names.include?('provider')
72
77
  attributes.reverse_merge!(provider: 'identity')
73
78
  end
79
+ @identity = model.new(attributes)
74
80
  if saving_instead_of_creating?
75
- @identity = model.new(attributes)
76
81
  env['omniauth.identity'] = @identity
77
82
  if !validating? || valid?
78
83
  @identity.save
79
84
  registration_result
80
85
  else
81
- registration_failure('Validation failed')
86
+ registration_failure(options[:validation_failure_message])
82
87
  end
83
88
  else
84
89
  deprecated_registration(attributes)
@@ -114,19 +119,19 @@ module OmniAuth
114
119
 
115
120
  def build_omniauth_login_form
116
121
  OmniAuth::Form.build(
117
- title: (options[:title] || 'Identity Verification'),
122
+ title: options[:title],
118
123
  url: callback_path
119
124
  ) do |f|
120
125
  f.text_field 'Login', 'auth_key'
121
126
  f.password_field 'Password', 'password'
122
127
  if options[:enable_registration]
123
- f.html "<p align='center'><a href='#{registration_path}'>Create an Identity</a></p>"
128
+ f.html "<p align='center'><a href='#{registration_path}'>#{options[:create_identity_link_text]}</a></p>"
124
129
  end
125
130
  end
126
131
  end
127
132
 
128
133
  def build_omniauth_registration_form(validation_message)
129
- OmniAuth::Form.build(title: 'Register Identity') do |f|
134
+ OmniAuth::Form.build(title: options[:registration_form_title]) do |f|
130
135
  f.html "<p style='color:red'>#{validation_message}</p>" if validation_message
131
136
  options[:fields].each do |field|
132
137
  f.text_field field.to_s.capitalize, field.to_s
@@ -137,14 +142,14 @@ module OmniAuth
137
142
  end
138
143
 
139
144
  def saving_instead_of_creating?
140
- model.respond_to?(:save) && model.respond_to?(:persisted?)
145
+ @identity.respond_to?(:save) && @identity.respond_to?(:persisted?)
141
146
  end
142
147
 
143
148
  # Validates the model before it is persisted
144
149
  #
145
150
  # @return [truthy or falsey] :on_validation option is truthy or falsey
146
151
  def validating?
147
- options[:on_validation]
152
+ !!options[:on_validation]
148
153
  end
149
154
 
150
155
  # Validates the model before it is persisted
@@ -169,7 +174,7 @@ module OmniAuth
169
174
  env['PATH_INFO'] = callback_path
170
175
  callback_phase
171
176
  else
172
- registration_failure('One or more fields were invalid')
177
+ registration_failure(options[:registration_failure_message])
173
178
  end
174
179
  end
175
180
 
@@ -3,8 +3,9 @@
3
3
  RSpec.describe OmniAuth::Strategies::Identity do
4
4
  attr_accessor :app
5
5
 
6
- let(:auth_hash) { last_response.headers['env']['omniauth.auth'] }
7
- let(:identity_hash) { last_response.headers['env']['omniauth.identity'] }
6
+ let(:env_hash) { last_response.headers['env'] }
7
+ let(:auth_hash) { env_hash['omniauth.auth'] }
8
+ let(:identity_hash) { env_hash['omniauth.identity'] }
8
9
  let(:identity_options) { {} }
9
10
  let(:anon_ar) do
10
11
  AnonymousActiveRecord.generate(
@@ -193,7 +194,7 @@ RSpec.describe OmniAuth::Strategies::Identity do
193
194
  end
194
195
  end
195
196
 
196
- context 'with successful creation' do
197
+ context 'with good identity' do
197
198
  let(:properties) do
198
199
  {
199
200
  name: 'Awesome Dude',
@@ -209,9 +210,66 @@ RSpec.describe OmniAuth::Strategies::Identity do
209
210
  expect(auth_hash['uid']).to match(/\d+/)
210
211
  expect(auth_hash['provider']).to eq('identity')
211
212
  end
213
+
214
+ context 'with on_validation proc' do
215
+ let(:identity_options) do
216
+ { model: anon_ar, on_validation: on_validation_proc }
217
+ end
218
+ let(:on_validation_proc) do
219
+ lambda { |_env|
220
+ false
221
+ }
222
+ end
223
+
224
+ context 'when validation fails' do
225
+ it 'does not set the env hash' do
226
+ post '/auth/identity/register', properties
227
+ expect(env_hash).to eq(nil)
228
+ end
229
+
230
+ it 'renders registration form' do
231
+ post '/auth/identity/register', properties
232
+ expect(last_response.body).to be_include(described_class.default_options[:registration_form_title])
233
+ end
234
+
235
+ it 'displays validation failure message' do
236
+ post '/auth/identity/register', properties
237
+ expect(last_response.body).to be_include(described_class.default_options[:validation_failure_message])
238
+ end
239
+ end
240
+
241
+ context 'when validation succeeds' do
242
+ let(:on_validation_proc) do
243
+ lambda { |_env|
244
+ true
245
+ }
246
+ end
247
+
248
+ it 'sets the auth hash' do
249
+ post '/auth/identity/register', properties
250
+ expect(auth_hash['uid']).to match(/\d+/)
251
+ expect(auth_hash['provider']).to eq('identity')
252
+ end
253
+
254
+ it 'does not render registration form' do
255
+ post '/auth/identity/register', properties
256
+ expect(last_response.body).not_to be_include(described_class.default_options[:registration_form_title])
257
+ end
258
+
259
+ it 'does not display validation failure message' do
260
+ post '/auth/identity/register', properties
261
+ expect(last_response.body).not_to be_include(described_class.default_options[:validation_failure_message])
262
+ end
263
+
264
+ it 'does not display registration failure message' do
265
+ post '/auth/identity/register', properties
266
+ expect(last_response.body).not_to be_include(described_class.default_options[:registration_failure_message])
267
+ end
268
+ end
269
+ end
212
270
  end
213
271
 
214
- context 'with invalid identity' do
272
+ context 'with bad identity' do
215
273
  let(:properties) do
216
274
  {
217
275
  name: 'Awesome Dude',
@@ -249,6 +307,62 @@ RSpec.describe OmniAuth::Strategies::Identity do
249
307
  expect(last_response.body).not_to be_include('One or more fields were invalid')
250
308
  end
251
309
  end
310
+
311
+ context 'with on_validation proc' do
312
+ let(:identity_options) do
313
+ { model: anon_ar, on_validation: on_validation_proc }
314
+ end
315
+ let(:on_validation_proc) do
316
+ lambda { |_env|
317
+ false
318
+ }
319
+ end
320
+
321
+ context 'when validation fails' do
322
+ it 'does not set the env hash' do
323
+ post '/auth/identity/register', properties
324
+ expect(env_hash).to eq(nil)
325
+ end
326
+
327
+ it 'renders registration form' do
328
+ post '/auth/identity/register', properties
329
+ expect(last_response.body).to be_include(described_class.default_options[:registration_form_title])
330
+ end
331
+
332
+ it 'displays validation failure message' do
333
+ post '/auth/identity/register', properties
334
+ expect(last_response.body).to be_include(described_class.default_options[:validation_failure_message])
335
+ end
336
+ end
337
+
338
+ context 'when validation succeeds' do
339
+ let(:on_validation_proc) do
340
+ lambda { |_env|
341
+ true
342
+ }
343
+ end
344
+
345
+ it 'does not set the env hash' do
346
+ post '/auth/identity/register', properties
347
+ expect(env_hash).to eq(nil)
348
+ end
349
+
350
+ it 'renders registration form' do
351
+ post '/auth/identity/register', properties
352
+ expect(last_response.body).to be_include(described_class.default_options[:registration_form_title])
353
+ end
354
+
355
+ it 'does not display validation failure message' do
356
+ post '/auth/identity/register', properties
357
+ expect(last_response.body).not_to be_include(described_class.default_options[:validation_failure_message])
358
+ end
359
+
360
+ it 'display registration failure message' do
361
+ post '/auth/identity/register', properties
362
+ expect(last_response.body).to be_include(described_class.default_options[:registration_failure_message])
363
+ end
364
+ end
365
+ end
252
366
  end
253
367
  end
254
368
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-identity
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-03-20 00:00:00.000000000 Z
13
+ date: 2021-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bcrypt