sorcery 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sorcery might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE.md +20 -0
  3. data/.rubocop.yml +52 -2
  4. data/.rubocop_todo.yml +1 -429
  5. data/.travis.yml +11 -21
  6. data/CHANGELOG.md +16 -0
  7. data/Gemfile +2 -2
  8. data/{LICENSE.txt → LICENSE.md} +1 -1
  9. data/README.md +7 -1
  10. data/gemfiles/{active_record-rails40.gemfile → active_record_rails_40.gemfile} +1 -2
  11. data/gemfiles/{active_record-rails41.gemfile → active_record_rails_41.gemfile} +1 -2
  12. data/gemfiles/{active_record-rails42.gemfile → active_record_rails_42.gemfile} +1 -2
  13. data/lib/generators/sorcery/USAGE +1 -1
  14. data/lib/generators/sorcery/install_generator.rb +21 -21
  15. data/lib/generators/sorcery/templates/initializer.rb +19 -1
  16. data/lib/sorcery/adapters/active_record_adapter.rb +1 -1
  17. data/lib/sorcery/adapters/mongoid_adapter.rb +23 -11
  18. data/lib/sorcery/controller.rb +22 -16
  19. data/lib/sorcery/controller/config.rb +2 -0
  20. data/lib/sorcery/controller/submodules/activity_logging.rb +4 -0
  21. data/lib/sorcery/controller/submodules/external.rb +37 -33
  22. data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -0
  23. data/lib/sorcery/controller/submodules/remember_me.rb +1 -7
  24. data/lib/sorcery/controller/submodules/session_timeout.rb +25 -4
  25. data/lib/sorcery/crypto_providers/aes256.rb +1 -0
  26. data/lib/sorcery/crypto_providers/bcrypt.rb +2 -1
  27. data/lib/sorcery/engine.rb +10 -3
  28. data/lib/sorcery/model.rb +9 -6
  29. data/lib/sorcery/model/config.rb +3 -3
  30. data/lib/sorcery/model/submodules/brute_force_protection.rb +6 -7
  31. data/lib/sorcery/model/submodules/external.rb +4 -3
  32. data/lib/sorcery/model/submodules/magic_login.rb +29 -36
  33. data/lib/sorcery/model/submodules/reset_password.rb +5 -4
  34. data/lib/sorcery/model/submodules/user_activation.rb +1 -1
  35. data/lib/sorcery/protocols/oauth.rb +1 -0
  36. data/lib/sorcery/providers/auth0.rb +46 -0
  37. data/lib/sorcery/providers/heroku.rb +1 -0
  38. data/lib/sorcery/providers/instagram.rb +73 -0
  39. data/lib/sorcery/providers/linkedin.rb +1 -1
  40. data/lib/sorcery/providers/vk.rb +1 -1
  41. data/lib/sorcery/providers/wechat.rb +8 -6
  42. data/lib/sorcery/test_helpers/internal.rb +5 -4
  43. data/lib/sorcery/test_helpers/internal/rails.rb +11 -11
  44. data/lib/sorcery/version.rb +1 -1
  45. data/sorcery.gemspec +25 -9
  46. data/spec/active_record/user_activation_spec.rb +2 -2
  47. data/spec/active_record/user_activity_logging_spec.rb +2 -2
  48. data/spec/active_record/user_brute_force_protection_spec.rb +2 -2
  49. data/spec/active_record/user_magic_login_spec.rb +4 -4
  50. data/spec/active_record/user_oauth_spec.rb +2 -2
  51. data/spec/active_record/user_remember_me_spec.rb +2 -2
  52. data/spec/active_record/user_reset_password_spec.rb +2 -2
  53. data/spec/active_record/user_spec.rb +0 -10
  54. data/spec/controllers/controller_http_basic_auth_spec.rb +1 -1
  55. data/spec/controllers/controller_oauth2_spec.rb +195 -123
  56. data/spec/controllers/controller_oauth_spec.rb +7 -7
  57. data/spec/controllers/controller_remember_me_spec.rb +11 -6
  58. data/spec/controllers/controller_session_timeout_spec.rb +90 -3
  59. data/spec/controllers/controller_spec.rb +2 -2
  60. data/spec/orm/active_record.rb +2 -2
  61. data/spec/providers/vk_spec.rb +13 -12
  62. data/spec/rails_app/app/controllers/sorcery_controller.rb +83 -32
  63. data/spec/rails_app/app/mailers/sorcery_mailer.rb +1 -1
  64. data/spec/rails_app/config/application.rb +8 -3
  65. data/spec/rails_app/config/boot.rb +1 -1
  66. data/spec/rails_app/config/environment.rb +1 -1
  67. data/spec/rails_app/config/routes.rb +7 -0
  68. data/spec/rails_app/config/secrets.yml +4 -0
  69. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -2
  70. data/spec/rails_app/db/migrate/invalidate_active_sessions/20180221093235_add_invalidate_active_sessions_before_to_users.rb +9 -0
  71. data/spec/rails_app/db/migrate/magic_login/20170924151831_add_magic_login_to_users.rb +3 -3
  72. data/spec/rails_app/db/schema.rb +7 -9
  73. data/spec/shared_examples/user_magic_login_shared_examples.rb +50 -50
  74. data/spec/shared_examples/user_oauth_shared_examples.rb +1 -1
  75. data/spec/shared_examples/user_remember_me_shared_examples.rb +1 -1
  76. data/spec/shared_examples/user_reset_password_shared_examples.rb +3 -3
  77. data/spec/shared_examples/user_shared_examples.rb +41 -43
  78. data/spec/sorcery_crypto_providers_spec.rb +1 -1
  79. data/spec/spec.opts +1 -1
  80. data/spec/spec_helper.rb +2 -2
  81. data/spec/support/migration_helper.rb +19 -0
  82. metadata +60 -38
  83. data/spec/rails_app/config/initializers/secret_token.rb +0 -7
@@ -1,3 +1,3 @@
1
1
  module Sorcery
2
- VERSION = '0.12.0'
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -1,34 +1,50 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'sorcery/version'
4
4
 
5
+ # rubocop:disable Metrics/BlockLength
5
6
  Gem::Specification.new do |s|
6
7
  s.name = 'sorcery'
7
8
  s.version = Sorcery::VERSION
8
- s.authors = ['Noam Ben Ari', 'Kir Shatrov', 'Grzegorz Witek', 'Chase Gilliam']
9
- s.email = 'chase.gilliam@gmail.com'
9
+ s.authors = [
10
+ 'Noam Ben Ari',
11
+ 'Kir Shatrov',
12
+ 'Grzegorz Witek',
13
+ 'Chase Gilliam',
14
+ 'Josh Buker'
15
+ ]
16
+ s.email = [
17
+ 'chase.gilliam@gmail.com',
18
+ 'contact@joshbuker.com'
19
+ ]
20
+
21
+ # TODO: Cleanup formatting.
22
+ # rubocop:disable Metrics/LineLength
10
23
  s.description = 'Provides common authentication needs such as signing in/out, activating by email and resetting password.'
11
24
  s.summary = 'Magical authentication for Rails applications'
12
25
  s.homepage = 'https://github.com/Sorcery/sorcery'
13
26
  s.post_install_message = "As of version 1.0 oauth/oauth2 won't be automatically bundled so you may need to add those dependencies to your Gemfile.\n"
14
27
  s.post_install_message += 'You may need oauth2 if you use external providers such as any of these: https://github.com/Sorcery/sorcery/tree/master/lib/sorcery/providers'
28
+ # rubocop:enable Metrics/LineLength
15
29
 
16
30
  s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
31
  s.require_paths = ['lib']
18
32
 
19
33
  s.licenses = ['MIT']
20
34
 
21
- s.required_ruby_version = '>= 2.2.2'
35
+ s.required_ruby_version = '>= 2.2.9'
22
36
 
37
+ s.add_dependency 'bcrypt', '~> 3.1'
23
38
  s.add_dependency 'oauth', '~> 0.4', '>= 0.4.4'
24
39
  s.add_dependency 'oauth2', '~> 1.0', '>= 0.8.0'
25
- s.add_dependency 'bcrypt', '~> 3.1'
26
40
 
27
- s.add_development_dependency 'yard', '~> 0.9.0', '>= 0.9.12'
28
- s.add_development_dependency 'timecop'
29
- s.add_development_dependency 'simplecov', '>= 0.3.8'
41
+ s.add_development_dependency 'byebug', '~> 10.0.0'
30
42
  s.add_development_dependency 'rspec-rails', '~> 3.7.0'
43
+ s.add_development_dependency 'rubocop'
44
+ s.add_development_dependency 'simplecov', '>= 0.3.8'
31
45
  s.add_development_dependency 'test-unit', '~> 3.2.0'
32
- s.add_development_dependency 'byebug', '~> 10.0.0'
46
+ s.add_development_dependency 'timecop'
33
47
  s.add_development_dependency 'webmock', '~> 3.3.0'
48
+ s.add_development_dependency 'yard', '~> 0.9.0', '>= 0.9.12'
34
49
  end
50
+ # rubocop:enable Metrics/BlockLength
@@ -5,12 +5,12 @@ require 'shared_examples/user_activation_shared_examples'
5
5
 
6
6
  describe User, 'with activation submodule', active_record: true do
7
7
  before(:all) do
8
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
8
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
9
9
  User.reset_column_information
10
10
  end
11
11
 
12
12
  after(:all) do
13
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
13
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
14
14
  end
15
15
 
16
16
  it_behaves_like 'rails_3_activation_model'
@@ -3,12 +3,12 @@ require 'shared_examples/user_activity_logging_shared_examples'
3
3
 
4
4
  describe User, 'with activity logging submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activity_logging")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/activity_logging")
7
7
  User.reset_column_information
8
8
  end
9
9
 
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/activity_logging")
12
12
  end
13
13
 
14
14
  it_behaves_like 'rails_3_activity_logging_model'
@@ -3,12 +3,12 @@ require 'shared_examples/user_brute_force_protection_shared_examples'
3
3
 
4
4
  describe User, 'with brute_force_protection submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/brute_force_protection")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/brute_force_protection")
7
7
  User.reset_column_information
8
8
  end
9
9
 
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/brute_force_protection")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/brute_force_protection")
12
12
  end
13
13
 
14
14
  it_behaves_like 'rails_3_brute_force_protection_model'
@@ -3,13 +3,13 @@ require 'shared_examples/user_magic_login_shared_examples'
3
3
 
4
4
  describe User, 'with magic_login submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/magic_login")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/magic_login")
7
7
  User.reset_column_information
8
8
  end
9
-
9
+
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/magic_login")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/magic_login")
12
12
  end
13
-
13
+
14
14
  it_behaves_like 'magic_login_model'
15
15
  end
@@ -3,12 +3,12 @@ require 'shared_examples/user_oauth_shared_examples'
3
3
 
4
4
  describe User, 'with oauth submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
7
7
  User.reset_column_information
8
8
  end
9
9
 
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
12
12
  end
13
13
 
14
14
  it_behaves_like 'rails_3_oauth_model'
@@ -3,12 +3,12 @@ require 'shared_examples/user_remember_me_shared_examples'
3
3
 
4
4
  describe User, 'with remember_me submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/remember_me")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/remember_me")
7
7
  User.reset_column_information
8
8
  end
9
9
 
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/remember_me")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/remember_me")
12
12
  end
13
13
 
14
14
  it_behaves_like 'rails_3_remember_me_model'
@@ -3,12 +3,12 @@ require 'shared_examples/user_reset_password_shared_examples'
3
3
 
4
4
  describe User, 'with reset_password submodule', active_record: true do
5
5
  before(:all) do
6
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/reset_password")
6
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/reset_password")
7
7
  User.reset_column_information
8
8
  end
9
9
 
10
10
  after(:all) do
11
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/reset_password")
11
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/reset_password")
12
12
  end
13
13
 
14
14
  it_behaves_like 'rails_3_reset_password_model'
@@ -22,16 +22,6 @@ describe User, 'with no submodules (core)', active_record: true do
22
22
  it_should_behave_like 'rails_3_core_model'
23
23
 
24
24
  describe 'external users' do
25
- before(:all) do
26
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
27
- User.reset_column_information
28
- sorcery_reload!
29
- end
30
-
31
- after(:all) do
32
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
33
- end
34
-
35
25
  it_should_behave_like 'external_user'
36
26
  end
37
27
  end
@@ -28,7 +28,7 @@ describe SorceryController, type: :controller do
28
28
  expect(User).to receive('authenticate').with('bla@bla.com', 'secret').and_return(user)
29
29
  get :test_http_basic_auth, params: {}, session: { http_authentication_used: true }
30
30
 
31
- expect(response).to be_a_success
31
+ expect(response).to be_successful
32
32
  end
33
33
 
34
34
  it 'fails authentication if credentials are wrong' do
@@ -5,7 +5,9 @@ require 'spec_helper'
5
5
  describe SorceryController, active_record: true, type: :controller do
6
6
  before(:all) do
7
7
  if SORCERY_ORM == :active_record
8
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/external")
8
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/external")
9
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/activation")
10
+ MigrationHelper.migrate("#{Rails.root}/db/migrate/activity_logging")
9
11
  User.reset_column_information
10
12
  end
11
13
 
@@ -15,7 +17,9 @@ describe SorceryController, active_record: true, type: :controller do
15
17
 
16
18
  after(:all) do
17
19
  if SORCERY_ORM == :active_record
18
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
20
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/external")
21
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/activity_logging")
22
+ MigrationHelper.rollback("#{Rails.root}/db/migrate/activation")
19
23
  end
20
24
  end
21
25
 
@@ -151,7 +155,7 @@ describe SorceryController, active_record: true, type: :controller do
151
155
  expect(flash[:notice]).to eq 'Success!'
152
156
  end
153
157
 
154
- [:github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft].each do |provider|
158
+ %i[github google liveid vk salesforce paypal slack wechat microsoft instagram auth0].each do |provider|
155
159
  describe "with #{provider}" do
156
160
  it 'login_at redirects correctly' do
157
161
  get :"login_at_test_#{provider}"
@@ -196,51 +200,63 @@ describe SorceryController, active_record: true, type: :controller do
196
200
 
197
201
  describe 'OAuth with User Activation features' do
198
202
  before(:all) do
199
- if SORCERY_ORM == :active_record
200
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/activation")
201
- end
202
-
203
- sorcery_reload!([:user_activation,:external], :user_activation_mailer => ::SorceryMailer)
204
- sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft])
203
+ sorcery_reload!(%i[user_activation external], user_activation_mailer: ::SorceryMailer)
204
+ sorcery_controller_property_set(
205
+ :external_providers,
206
+ %i[
207
+ facebook
208
+ github
209
+ google
210
+ liveid
211
+ vk
212
+ salesforce
213
+ paypal
214
+ slack
215
+ wechat
216
+ microsoft
217
+ instagram
218
+ auth0
219
+ ]
220
+ )
205
221
 
206
222
  # TODO: refactor
207
- sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
208
- sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
209
- sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
210
- sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
211
- sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
212
- sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
213
- sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
214
- sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
215
- sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
216
- sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
217
- sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
218
- sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
219
- sorcery_controller_external_property_set(:vk, :key, "eYVNBjBDi33aa9GkA3w")
220
- sorcery_controller_external_property_set(:vk, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
221
- sorcery_controller_external_property_set(:vk, :callback_url, "http://blabla.com")
222
- sorcery_controller_external_property_set(:salesforce, :key, "eYVNBjBDi33aa9GkA3w")
223
- sorcery_controller_external_property_set(:salesforce, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
224
- sorcery_controller_external_property_set(:salesforce, :callback_url, "http://blabla.com")
225
- sorcery_controller_external_property_set(:paypal, :key, "eYVNBjBDi33aa9GkA3w")
226
- sorcery_controller_external_property_set(:paypal, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
227
- sorcery_controller_external_property_set(:paypal, :callback_url, "http://blabla.com")
228
- sorcery_controller_external_property_set(:slack, :key, "eYVNBjBDi33aa9GkA3w")
229
- sorcery_controller_external_property_set(:slack, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
230
- sorcery_controller_external_property_set(:slack, :callback_url, "http://blabla.com")
231
- sorcery_controller_external_property_set(:wechat, :key, "eYVNBjBDi33aa9GkA3w")
232
- sorcery_controller_external_property_set(:wechat, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
233
- sorcery_controller_external_property_set(:wechat, :callback_url, "http://blabla.com")
234
- sorcery_controller_external_property_set(:microsoft, :key, "eYVNBjBDi33aa9GkA3w")
235
- sorcery_controller_external_property_set(:microsoft, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
236
- sorcery_controller_external_property_set(:microsoft, :callback_url, "http://blabla.com")
237
- end
238
-
239
- after(:all) do
240
- if SORCERY_ORM == :active_record
241
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
242
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activation")
243
- end
223
+ sorcery_controller_external_property_set(:facebook, :key, 'eYVNBjBDi33aa9GkA3w')
224
+ sorcery_controller_external_property_set(:facebook, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
225
+ sorcery_controller_external_property_set(:facebook, :callback_url, 'http://blabla.com')
226
+ sorcery_controller_external_property_set(:github, :key, 'eYVNBjBDi33aa9GkA3w')
227
+ sorcery_controller_external_property_set(:github, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
228
+ sorcery_controller_external_property_set(:github, :callback_url, 'http://blabla.com')
229
+ sorcery_controller_external_property_set(:google, :key, 'eYVNBjBDi33aa9GkA3w')
230
+ sorcery_controller_external_property_set(:google, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
231
+ sorcery_controller_external_property_set(:google, :callback_url, 'http://blabla.com')
232
+ sorcery_controller_external_property_set(:liveid, :key, 'eYVNBjBDi33aa9GkA3w')
233
+ sorcery_controller_external_property_set(:liveid, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
234
+ sorcery_controller_external_property_set(:liveid, :callback_url, 'http://blabla.com')
235
+ sorcery_controller_external_property_set(:vk, :key, 'eYVNBjBDi33aa9GkA3w')
236
+ sorcery_controller_external_property_set(:vk, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
237
+ sorcery_controller_external_property_set(:vk, :callback_url, 'http://blabla.com')
238
+ sorcery_controller_external_property_set(:salesforce, :key, 'eYVNBjBDi33aa9GkA3w')
239
+ sorcery_controller_external_property_set(:salesforce, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
240
+ sorcery_controller_external_property_set(:salesforce, :callback_url, 'http://blabla.com')
241
+ sorcery_controller_external_property_set(:paypal, :key, 'eYVNBjBDi33aa9GkA3w')
242
+ sorcery_controller_external_property_set(:paypal, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
243
+ sorcery_controller_external_property_set(:paypal, :callback_url, 'http://blabla.com')
244
+ sorcery_controller_external_property_set(:slack, :key, 'eYVNBjBDi33aa9GkA3w')
245
+ sorcery_controller_external_property_set(:slack, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
246
+ sorcery_controller_external_property_set(:slack, :callback_url, 'http://blabla.com')
247
+ sorcery_controller_external_property_set(:wechat, :key, 'eYVNBjBDi33aa9GkA3w')
248
+ sorcery_controller_external_property_set(:wechat, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
249
+ sorcery_controller_external_property_set(:wechat, :callback_url, 'http://blabla.com')
250
+ sorcery_controller_external_property_set(:microsoft, :key, 'eYVNBjBDi33aa9GkA3w')
251
+ sorcery_controller_external_property_set(:microsoft, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
252
+ sorcery_controller_external_property_set(:microsoft, :callback_url, 'http://blabla.com')
253
+ sorcery_controller_external_property_set(:instagram, :key, 'eYVNBjBDi33aa9GkA3w')
254
+ sorcery_controller_external_property_set(:instagram, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
255
+ sorcery_controller_external_property_set(:instagram, :callback_url, 'http://blabla.com')
256
+ sorcery_controller_external_property_set(:auth0, :key, 'eYVNBjBDi33aa9GkA3w')
257
+ sorcery_controller_external_property_set(:auth0, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
258
+ sorcery_controller_external_property_set(:auth0, :callback_url, 'http://blabla.com')
259
+ sorcery_controller_external_property_set(:auth0, :site, 'https://sorcery-test.auth0.com')
244
260
  end
245
261
 
246
262
  after(:each) do
@@ -263,7 +279,7 @@ describe SorceryController, active_record: true, type: :controller do
263
279
  expect(ActionMailer::Base.deliveries.size).to eq old_size
264
280
  end
265
281
 
266
- [:github, :google, :liveid, :vk, :salesforce, :paypal, :wechat, :microsoft].each do |provider|
282
+ %i[github google liveid vk salesforce paypal wechat microsoft instagram auth0].each do |provider|
267
283
  it "does not send activation email to external users (#{provider})" do
268
284
  old_size = ActionMailer::Base.deliveries.size
269
285
  create_new_external_user provider
@@ -275,6 +291,7 @@ describe SorceryController, active_record: true, type: :controller do
275
291
  create_new_external_user provider
276
292
  old_size = ActionMailer::Base.deliveries.size
277
293
  @user.activate!
294
+ expect(ActionMailer::Base.deliveries.size).to eq old_size
278
295
  end
279
296
  end
280
297
  end
@@ -283,17 +300,10 @@ describe SorceryController, active_record: true, type: :controller do
283
300
  let(:user) { double('user', id: 42) }
284
301
 
285
302
  before(:all) do
286
- sorcery_reload!([:activity_logging, :external])
287
- end
288
-
289
- after(:all) do
290
- if SORCERY_ORM == :active_record
291
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/external")
292
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/activity_logging")
293
- end
303
+ sorcery_reload!(%i[activity_logging external])
294
304
  end
295
305
 
296
- %w(facebook github google liveid vk salesforce slack).each do |provider|
306
+ %w[facebook github google liveid vk salesforce slack].each do |provider|
297
307
  context "when #{provider}" do
298
308
  before(:each) do
299
309
  sorcery_controller_property_set(:register_login_time, true)
@@ -327,12 +337,12 @@ describe SorceryController, active_record: true, type: :controller do
327
337
 
328
338
  describe 'OAuth with session timeout features' do
329
339
  before(:all) do
330
- sorcery_reload!([:session_timeout, :external])
340
+ sorcery_reload!(%i[session_timeout external])
331
341
  end
332
342
 
333
343
  let(:user) { double('user', id: 42) }
334
344
 
335
- %w(facebook github google liveid vk salesforce slack).each do |provider|
345
+ %w[facebook github google liveid vk salesforce slack].each do |provider|
336
346
  context "when #{provider}" do
337
347
  before(:each) do
338
348
  sorcery_model_property_set(:authentications_class, Authentication)
@@ -369,41 +379,78 @@ describe SorceryController, active_record: true, type: :controller do
369
379
  def stub_all_oauth2_requests!
370
380
  access_token = double(OAuth2::AccessToken)
371
381
  allow(access_token).to receive(:token_param=)
382
+ # Needed for Instagram
383
+ allow(access_token).to receive(:[]).with(:client_id) { 'eYVNBjBDi33aa9GkA3w' }
372
384
  response = double(OAuth2::Response)
373
385
  allow(response).to receive(:body) {
374
- {
375
- 'id' => '123',
376
- 'user_id' => '123', # Needed for Salesforce
377
- 'name' => 'Noam Ben Ari',
378
- 'first_name' => 'Noam',
379
- 'last_name' => 'Ben Ari',
380
- 'link' => 'http://www.facebook.com/nbenari1',
381
- 'hometown' => { 'id' => '110619208966868', 'name' => 'Haifa, Israel' },
382
- 'location' => { 'id' => '106906559341067', 'name' => 'Pardes Hanah, Hefa, Israel' },
383
- 'bio' => "I'm a new daddy, and enjoying it!",
384
- 'gender' => 'male',
385
- 'email' => 'nbenari@gmail.com',
386
- 'timezone' => 2,
387
- 'locale' => 'en_US',
388
- 'languages' => [{ 'id' => '108405449189952', 'name' => 'Hebrew' }, { 'id' => '106059522759137', 'name' => 'English' }, { 'id' => '112624162082677', 'name' => 'Russian' }],
389
- 'verified' => true,
390
- 'updated_time' => '2011-02-16T20:59:38+0000',
391
- # response for VK auth
392
- 'response' => [
393
- {
394
- 'uid' => '123',
395
- 'first_name' => 'Noam',
396
- 'last_name' => 'Ben Ari'
397
- }
398
- ],
399
- 'user' => {
400
- 'name' => 'Sonny Whether',
401
- 'id' => '123',
402
- 'email' => 'bobby@example.com'
403
- },
404
- # response for wechat auth
405
- 'unionid' => '123',
406
- }.to_json }
386
+ {
387
+ 'id' => '123',
388
+ 'user_id' => '123', # Needed for Salesforce
389
+ 'sub' => '123', # Needed for Auth0
390
+ 'name' => 'Noam Ben Ari',
391
+ 'first_name' => 'Noam',
392
+ 'last_name' => 'Ben Ari',
393
+ 'link' => 'http://www.facebook.com/nbenari1',
394
+ 'hometown' => {
395
+ 'id' => '110619208966868',
396
+ 'name' => 'Haifa, Israel'
397
+ },
398
+ 'location' => {
399
+ 'id' => '106906559341067',
400
+ 'name' => 'Pardes Hanah, Hefa, Israel'
401
+ },
402
+ 'bio' => "I'm a new daddy, and enjoying it!",
403
+ 'gender' => 'male',
404
+ 'email' => 'nbenari@gmail.com',
405
+ 'timezone' => 2,
406
+ 'locale' => 'en_US',
407
+ 'languages' => [
408
+ {
409
+ 'id' => '108405449189952',
410
+ 'name' => 'Hebrew'
411
+ },
412
+ {
413
+ 'id' => '106059522759137',
414
+ 'name' => 'English'
415
+ },
416
+ {
417
+ 'id' => '112624162082677',
418
+ 'name' => 'Russian'
419
+ }
420
+ ],
421
+ 'verified' => true,
422
+ 'updated_time' => '2011-02-16T20:59:38+0000',
423
+ # response for VK auth
424
+ 'response' => [
425
+ {
426
+ 'uid' => '123',
427
+ 'first_name' => 'Noam',
428
+ 'last_name' => 'Ben Ari'
429
+ }
430
+ ],
431
+ 'user' => {
432
+ 'name' => 'Sonny Whether',
433
+ 'id' => '123',
434
+ 'email' => 'bobby@example.com'
435
+ },
436
+ # response for wechat auth
437
+ 'unionid' => '123',
438
+ # response for instagram
439
+ 'data' => {
440
+ 'username' => 'pnmahoney',
441
+ 'bio' => 'turn WHAT down?',
442
+ 'website' => '',
443
+ 'profile_picture' => 'http://photos-d.ak.instagram.com/hphotos-ak-xpa1/10454121_417985815007395_867850883_a.jpg',
444
+ 'full_name' => 'Patrick Mahoney',
445
+ 'counts' => {
446
+ 'media' => 2,
447
+ 'followed_by' => 100,
448
+ 'follows' => 71
449
+ },
450
+ 'id' => '123'
451
+ }
452
+ }.to_json
453
+ }
407
454
  allow(access_token).to receive(:get) { response }
408
455
  allow(access_token).to receive(:token) { '187041a618229fdaf16613e96e1caabc1e86e46bbfad228de41520e63fe45873684c365a14417289599f3' }
409
456
  # access_token params for VK auth
@@ -412,37 +459,60 @@ describe SorceryController, active_record: true, type: :controller do
412
459
  end
413
460
 
414
461
  def set_external_property
415
- sorcery_controller_property_set(:external_providers, [:facebook, :github, :google, :liveid, :vk, :salesforce, :paypal, :slack, :wechat, :microsoft])
416
- sorcery_controller_external_property_set(:facebook, :key, "eYVNBjBDi33aa9GkA3w")
417
- sorcery_controller_external_property_set(:facebook, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
418
- sorcery_controller_external_property_set(:facebook, :callback_url, "http://blabla.com")
419
- sorcery_controller_external_property_set(:github, :key, "eYVNBjBDi33aa9GkA3w")
420
- sorcery_controller_external_property_set(:github, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
421
- sorcery_controller_external_property_set(:github, :callback_url, "http://blabla.com")
422
- sorcery_controller_external_property_set(:google, :key, "eYVNBjBDi33aa9GkA3w")
423
- sorcery_controller_external_property_set(:google, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
424
- sorcery_controller_external_property_set(:google, :callback_url, "http://blabla.com")
425
- sorcery_controller_external_property_set(:liveid, :key, "eYVNBjBDi33aa9GkA3w")
426
- sorcery_controller_external_property_set(:liveid, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
427
- sorcery_controller_external_property_set(:liveid, :callback_url, "http://blabla.com")
428
- sorcery_controller_external_property_set(:vk, :key, "eYVNBjBDi33aa9GkA3w")
429
- sorcery_controller_external_property_set(:vk, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
430
- sorcery_controller_external_property_set(:vk, :callback_url, "http://blabla.com")
431
- sorcery_controller_external_property_set(:salesforce, :key, "eYVNBjBDi33aa9GkA3w")
432
- sorcery_controller_external_property_set(:salesforce, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
433
- sorcery_controller_external_property_set(:salesforce, :callback_url, "http://blabla.com")
434
- sorcery_controller_external_property_set(:paypal, :key, "eYVNBjBDi33aa9GkA3w")
435
- sorcery_controller_external_property_set(:paypal, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
436
- sorcery_controller_external_property_set(:paypal, :callback_url, "http://blabla.com")
437
- sorcery_controller_external_property_set(:slack, :key, "eYVNBjBDi33aa9GkA3w")
438
- sorcery_controller_external_property_set(:slack, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
439
- sorcery_controller_external_property_set(:slack, :callback_url, "http://blabla.com")
440
- sorcery_controller_external_property_set(:wechat, :key, "eYVNBjBDi33aa9GkA3w")
441
- sorcery_controller_external_property_set(:wechat, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
442
- sorcery_controller_external_property_set(:wechat, :callback_url, "http://blabla.com")
443
- sorcery_controller_external_property_set(:microsoft, :key, "eYVNBjBDi33aa9GkA3w")
444
- sorcery_controller_external_property_set(:microsoft, :secret, "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8")
445
- sorcery_controller_external_property_set(:microsoft, :callback_url, "http://blabla.com")
462
+ sorcery_controller_property_set(
463
+ :external_providers,
464
+ %i[
465
+ facebook
466
+ github
467
+ google
468
+ liveid
469
+ vk
470
+ salesforce
471
+ paypal
472
+ slack
473
+ wechat
474
+ microsoft
475
+ instagram
476
+ auth0
477
+ ]
478
+ )
479
+ sorcery_controller_external_property_set(:facebook, :key, 'eYVNBjBDi33aa9GkA3w')
480
+ sorcery_controller_external_property_set(:facebook, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
481
+ sorcery_controller_external_property_set(:facebook, :callback_url, 'http://blabla.com')
482
+ sorcery_controller_external_property_set(:github, :key, 'eYVNBjBDi33aa9GkA3w')
483
+ sorcery_controller_external_property_set(:github, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
484
+ sorcery_controller_external_property_set(:github, :callback_url, 'http://blabla.com')
485
+ sorcery_controller_external_property_set(:google, :key, 'eYVNBjBDi33aa9GkA3w')
486
+ sorcery_controller_external_property_set(:google, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
487
+ sorcery_controller_external_property_set(:google, :callback_url, 'http://blabla.com')
488
+ sorcery_controller_external_property_set(:liveid, :key, 'eYVNBjBDi33aa9GkA3w')
489
+ sorcery_controller_external_property_set(:liveid, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
490
+ sorcery_controller_external_property_set(:liveid, :callback_url, 'http://blabla.com')
491
+ sorcery_controller_external_property_set(:vk, :key, 'eYVNBjBDi33aa9GkA3w')
492
+ sorcery_controller_external_property_set(:vk, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
493
+ sorcery_controller_external_property_set(:vk, :callback_url, 'http://blabla.com')
494
+ sorcery_controller_external_property_set(:salesforce, :key, 'eYVNBjBDi33aa9GkA3w')
495
+ sorcery_controller_external_property_set(:salesforce, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
496
+ sorcery_controller_external_property_set(:salesforce, :callback_url, 'http://blabla.com')
497
+ sorcery_controller_external_property_set(:paypal, :key, 'eYVNBjBDi33aa9GkA3w')
498
+ sorcery_controller_external_property_set(:paypal, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
499
+ sorcery_controller_external_property_set(:paypal, :callback_url, 'http://blabla.com')
500
+ sorcery_controller_external_property_set(:slack, :key, 'eYVNBjBDi33aa9GkA3w')
501
+ sorcery_controller_external_property_set(:slack, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
502
+ sorcery_controller_external_property_set(:slack, :callback_url, 'http://blabla.com')
503
+ sorcery_controller_external_property_set(:wechat, :key, 'eYVNBjBDi33aa9GkA3w')
504
+ sorcery_controller_external_property_set(:wechat, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
505
+ sorcery_controller_external_property_set(:wechat, :callback_url, 'http://blabla.com')
506
+ sorcery_controller_external_property_set(:microsoft, :key, 'eYVNBjBDi33aa9GkA3w')
507
+ sorcery_controller_external_property_set(:microsoft, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
508
+ sorcery_controller_external_property_set(:microsoft, :callback_url, 'http://blabla.com')
509
+ sorcery_controller_external_property_set(:instagram, :key, 'eYVNBjBDi33aa9GkA3w')
510
+ sorcery_controller_external_property_set(:instagram, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
511
+ sorcery_controller_external_property_set(:instagram, :callback_url, 'http://blabla.com')
512
+ sorcery_controller_external_property_set(:auth0, :key, 'eYVNBjBDi33aa9GkA3w')
513
+ sorcery_controller_external_property_set(:auth0, :secret, 'XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8')
514
+ sorcery_controller_external_property_set(:auth0, :callback_url, 'http://blabla.com')
515
+ sorcery_controller_external_property_set(:auth0, :site, 'https://sorcery-test.auth0.com')
446
516
  end
447
517
 
448
518
  def provider_url(provider)
@@ -455,7 +525,9 @@ describe SorceryController, active_record: true, type: :controller do
455
525
  salesforce: "https://login.salesforce.com/services/oauth2/authorize?client_id=#{::Sorcery::Controller::Config.salesforce.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope#{'=' + ::Sorcery::Controller::Config.salesforce.scope unless ::Sorcery::Controller::Config.salesforce.scope.nil?}&state",
456
526
  slack: "https://slack.com/oauth/authorize?client_id=#{::Sorcery::Controller::Config.slack.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=identity.basic%2C+identity.email&state",
457
527
  wechat: "https://open.weixin.qq.com/connect/qrconnect?appid=#{::Sorcery::Controller::Config.wechat.key}&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=snsapi_login&state=#wechat_redirect",
458
- microsoft: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=#{::Sorcery::Controller::Config.microsoft.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=openid+email+https%3A%2F%2Fgraph.microsoft.com%2FUser.Read&state"
528
+ microsoft: "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=#{::Sorcery::Controller::Config.microsoft.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=openid+email+https%3A%2F%2Fgraph.microsoft.com%2FUser.Read&state",
529
+ instagram: "https://api.instagram.com/oauth/authorize?client_id=#{::Sorcery::Controller::Config.instagram.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=#{::Sorcery::Controller::Config.instagram.scope}&state",
530
+ auth0: "https://sorcery-test.auth0.com/authorize?client_id=#{::Sorcery::Controller::Config.auth0.key}&display&redirect_uri=http%3A%2F%2Fblabla.com&response_type=code&scope=openid+profile+email&state"
459
531
  }[provider]
460
532
  end
461
533
  end