sorcery 0.8.5 → 0.8.6

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +60 -4
  4. data/CHANGELOG.md +15 -1
  5. data/Gemfile +9 -18
  6. data/Gemfile.rails4 +8 -10
  7. data/README.md +31 -11
  8. data/VERSION +1 -1
  9. data/gemfiles/active_record-rails41.gemfile +6 -0
  10. data/gemfiles/mongo_mapper-rails41.gemfile +8 -0
  11. data/gemfiles/mongoid-rails41.gemfile +11 -0
  12. data/lib/sorcery.rb +20 -28
  13. data/lib/sorcery/controller.rb +6 -11
  14. data/lib/sorcery/controller/submodules/external.rb +30 -15
  15. data/lib/sorcery/controller/submodules/session_timeout.rb +1 -1
  16. data/lib/sorcery/model.rb +102 -70
  17. data/lib/sorcery/model/adapters/active_record.rb +7 -2
  18. data/lib/sorcery/model/adapters/datamapper.rb +123 -0
  19. data/lib/sorcery/model/adapters/mongo_mapper.rb +8 -4
  20. data/lib/sorcery/model/adapters/mongoid.rb +6 -6
  21. data/lib/sorcery/model/submodules/activity_logging.rb +24 -0
  22. data/lib/sorcery/model/submodules/brute_force_protection.rb +16 -0
  23. data/lib/sorcery/model/submodules/remember_me.rb +19 -4
  24. data/lib/sorcery/model/submodules/reset_password.rb +30 -13
  25. data/lib/sorcery/model/submodules/user_activation.rb +53 -22
  26. data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
  27. data/lib/sorcery/protocols/oauth.rb +42 -0
  28. data/lib/sorcery/protocols/oauth2.rb +47 -0
  29. data/lib/sorcery/providers/base.rb +27 -0
  30. data/lib/sorcery/providers/facebook.rb +63 -0
  31. data/lib/sorcery/providers/github.rb +51 -0
  32. data/lib/sorcery/providers/google.rb +51 -0
  33. data/lib/sorcery/providers/linkedin.rb +66 -0
  34. data/lib/sorcery/providers/liveid.rb +53 -0
  35. data/lib/sorcery/providers/twitter.rb +59 -0
  36. data/lib/sorcery/providers/vk.rb +61 -0
  37. data/lib/sorcery/providers/xing.rb +64 -0
  38. data/lib/sorcery/test_helpers/internal.rb +3 -3
  39. data/lib/sorcery/test_helpers/internal/rails.rb +14 -3
  40. data/lib/sorcery/test_helpers/rails.rb +1 -10
  41. data/lib/sorcery/test_helpers/rails/controller.rb +17 -0
  42. data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
  43. data/sorcery.gemspec +14 -18
  44. data/spec/active_record/controller_activity_logging_spec.rb +5 -116
  45. data/spec/active_record/controller_brute_force_protection_spec.rb +69 -47
  46. data/spec/active_record/controller_http_basic_auth_spec.rb +24 -18
  47. data/spec/active_record/controller_oauth2_spec.rb +112 -187
  48. data/spec/active_record/controller_oauth_spec.rb +41 -37
  49. data/spec/active_record/controller_remember_me_spec.rb +39 -38
  50. data/spec/active_record/controller_session_timeout_spec.rb +31 -16
  51. data/spec/active_record/controller_spec.rb +4 -178
  52. data/spec/active_record/integration_spec.rb +1 -1
  53. data/spec/active_record/user_activation_spec.rb +1 -1
  54. data/spec/active_record/user_activity_logging_spec.rb +1 -1
  55. data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
  56. data/spec/active_record/user_oauth_spec.rb +1 -1
  57. data/spec/active_record/user_remember_me_spec.rb +1 -1
  58. data/spec/active_record/user_reset_password_spec.rb +1 -1
  59. data/spec/active_record/user_spec.rb +7 -8
  60. data/spec/datamapper/controller_activity_logging_spec.rb +17 -0
  61. data/spec/datamapper/controller_spec.rb +8 -0
  62. data/spec/datamapper/user_activation_spec.rb +10 -0
  63. data/spec/datamapper/user_activity_logging_spec.rb +9 -0
  64. data/spec/datamapper/user_brute_force_protection_spec.rb +9 -0
  65. data/spec/datamapper/user_oauth_spec.rb +9 -0
  66. data/spec/datamapper/user_remember_me_spec.rb +8 -0
  67. data/spec/datamapper/user_reset_password_spec.rb +8 -0
  68. data/spec/datamapper/user_spec.rb +27 -0
  69. data/spec/mongo_mapper/controller_spec.rb +4 -171
  70. data/spec/mongo_mapper/user_activation_spec.rb +1 -2
  71. data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
  72. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
  73. data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
  74. data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
  75. data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
  76. data/spec/mongo_mapper/user_spec.rb +7 -8
  77. data/spec/mongoid/controller_activity_logging_spec.rb +4 -99
  78. data/spec/mongoid/controller_spec.rb +4 -182
  79. data/spec/mongoid/user_activation_spec.rb +1 -2
  80. data/spec/mongoid/user_activity_logging_spec.rb +1 -2
  81. data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
  82. data/spec/mongoid/user_oauth_spec.rb +1 -2
  83. data/spec/mongoid/user_remember_me_spec.rb +1 -2
  84. data/spec/mongoid/user_reset_password_spec.rb +1 -2
  85. data/spec/mongoid/user_spec.rb +8 -9
  86. data/spec/orm/active_record.rb +2 -0
  87. data/spec/orm/datamapper.rb +34 -0
  88. data/spec/orm/mongo_mapper.rb +1 -0
  89. data/spec/orm/mongoid.rb +1 -0
  90. data/spec/rails_app/app/controllers/sorcery_controller.rb +64 -59
  91. data/spec/rails_app/app/datamapper/authentication.rb +8 -0
  92. data/spec/rails_app/app/datamapper/user.rb +7 -0
  93. data/spec/rails_app/config/routes.rb +18 -13
  94. data/spec/shared_examples/controller_activity_logging_shared_examples.rb +125 -0
  95. data/spec/shared_examples/controller_oauth2_shared_examples.rb +32 -36
  96. data/spec/shared_examples/controller_oauth_shared_examples.rb +19 -26
  97. data/spec/shared_examples/controller_shared_examples.rb +203 -0
  98. data/spec/shared_examples/user_activation_shared_examples.rb +107 -90
  99. data/spec/shared_examples/user_activity_logging_shared_examples.rb +10 -10
  100. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +14 -13
  101. data/spec/shared_examples/user_oauth_shared_examples.rb +23 -15
  102. data/spec/shared_examples/user_remember_me_shared_examples.rb +32 -23
  103. data/spec/shared_examples/user_reset_password_shared_examples.rb +136 -115
  104. data/spec/shared_examples/user_shared_examples.rb +206 -146
  105. data/spec/sorcery_crypto_providers_spec.rb +28 -28
  106. data/spec/spec_helper.rb +15 -6
  107. metadata +83 -127
  108. data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
  109. data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
  110. data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
  111. data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
  112. data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
  113. data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
  114. data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
  115. data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
  116. data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
  117. data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
  118. data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
  119. data/lib/sorcery/test_helpers.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ece0272de9fa2ea03bbc1be9b2f9aa3b80e0f870
4
- data.tar.gz: 5369015b55c79aab6aeeeae13328624a8e20b7c8
3
+ metadata.gz: 73519a45c58c078688dd72b3ef7dc52b2b05ba92
4
+ data.tar.gz: a715fe10e2de64c09d76ec93e658849dd3b9112b
5
5
  SHA512:
6
- metadata.gz: 1a45a1696ebbcf7e4e8e248918389a38ea4555c263f12e290b1fdfd92c4e413d9713c29bbe98aa909ab9cb8642ff3e872a15405e6db9398afdf4f940521f68d5
7
- data.tar.gz: aed312b559bbdecd335535df0814989b906d4768fe56382ae18a029f534fb0d9904e8540913e2c6dccc51de9d5e8d2096212a3dbf7f6b787df647987aa72076a
6
+ metadata.gz: 08d0df3e5b8970ec81233d6dbb373cdabb4ff0e219dce27c7c790756507a36d683557ca11d19b70ea8e85217646ef20259892b6e0ee55f8d35c7d25cfb8df636
7
+ data.tar.gz: 66cb33e9e89b23036e1470bf0b937da42e68828ecdb821bc736b471cf938c23fa9eb53911ac35050704748ebdfd1790caa27af12ee97fdd26b58c7fae4cf30f9
data/.gitignore CHANGED
@@ -51,4 +51,5 @@ spec/rails_app/log/*
51
51
  *.log
52
52
  *.sqlite3
53
53
  Gemfile*.lock
54
+ gemfiles/*.lock
54
55
  .ruby-version
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
+ - 2.1
5
6
 
6
7
  services: mongodb
7
8
 
@@ -9,7 +10,62 @@ gemfile:
9
10
  - Gemfile
10
11
  - Gemfile.rails4
11
12
 
12
- script:
13
- - "SORCERY_ORM=active_record bundle exec rake spec SPEC=spec/active_record"
14
- - "SORCERY_ORM=mongoid bundle exec rake spec SPEC=spec/mongoid"
15
- - "SORCERY_ORM=mongo_mapper bundle exec rake spec SPEC=spec/mongo_mapper"
13
+ env:
14
+ - "SORCERY_ORM=active_record"
15
+ - "SORCERY_ORM=mongoid"
16
+ - "SORCERY_ORM=mongo_mapper"
17
+ - "SORCERY_ORM=datamapper"
18
+
19
+ before_script:
20
+ - mysql -e 'create database sorcery_test;'
21
+
22
+ matrix:
23
+ exclude:
24
+ - rvm: 1.9.3
25
+ gemfile: Gemfile.rails4
26
+ env: "SORCERY_ORM=datamapper"
27
+
28
+ - rvm: 2.0.0
29
+ gemfile: Gemfile.rails4
30
+ env: "SORCERY_ORM=datamapper"
31
+
32
+ - rvm: 2.1
33
+ gemfile: Gemfile.rails4
34
+ env: "SORCERY_ORM=datamapper"
35
+
36
+ include:
37
+ - rvm: 1.9.3
38
+ gemfile: gemfiles/mongoid-rails41.gemfile
39
+ env: "SORCERY_ORM=mongoid"
40
+
41
+ - rvm: 2.0.0
42
+ gemfile: gemfiles/mongoid-rails41.gemfile
43
+ env: "SORCERY_ORM=mongoid"
44
+
45
+ - rvm: 2.1
46
+ gemfile: gemfiles/mongoid-rails41.gemfile
47
+ env: "SORCERY_ORM=mongoid"
48
+
49
+ - rvm: 1.9.3
50
+ gemfile: gemfiles/mongo_mapper-rails41.gemfile
51
+ env: "SORCERY_ORM=mongo_mapper"
52
+
53
+ - rvm: 2.0.0
54
+ gemfile: gemfiles/mongo_mapper-rails41.gemfile
55
+ env: "SORCERY_ORM=mongo_mapper"
56
+
57
+ - rvm: 2.1
58
+ gemfile: gemfiles/mongo_mapper-rails41.gemfile
59
+ env: "SORCERY_ORM=mongo_mapper"
60
+
61
+ - rvm: 1.9.3
62
+ gemfile: gemfiles/active_record-rails41.gemfile
63
+ env: "SORCERY_ORM=active_record"
64
+
65
+ - rvm: 2.0.0
66
+ gemfile: gemfiles/active_record-rails41.gemfile
67
+ env: "SORCERY_ORM=active_record"
68
+
69
+ - rvm: 2.1
70
+ gemfile: gemfiles/active_record-rails41.gemfile
71
+ env: "SORCERY_ORM=active_record"
@@ -1,6 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## 0.8.5 (not released)
3
+ ## 0.8.6 (not released)
4
+
5
+ * `current_user` returns `nil` instead of `false` if there's no user loggd in (#493)
6
+ * MongoMapper adapter does not override `save!` method anymore. However due to ORM's lack of support for `validate: false` in `save!`, the combination of `validate: false` and `raise_on_failure: true` is not possible in MongoMapper. The errors will not be raised in this situation. (#151)
7
+ * Fixed rename warnings for bcrypt-ruby
8
+ * The way Sorcery adapters are included has been changed due to problem with multiple `included` blocks error in `ActiveSupport::Concern` class (#527)
9
+ * Session timeout works with new cookie serializer introduced in Rails 4.1
10
+ * Rails 4.1 compatibility bugs were fixed, this version is fully supported (#538)
11
+ * VK providers now supports `scope` option
12
+ * Support for DataMapper added
13
+ * Helpers for integration tests were added
14
+ * Fixed problems with special characters in user login attributes (MongoMapper & Mongoid)
15
+ * Fixed remaining `password_confirmation` value - it is now cleared just like `password`
16
+
17
+ ## 0.8.5
4
18
  * Fixed add_provider_to_user with CamelCased authentications_class model (#382)
5
19
  * Fixed unlock_token_mailer_disabled to only disable automatic mailing (#467)
6
20
  * Make send_email_* methods easier to overwrite (#473)
data/Gemfile CHANGED
@@ -1,24 +1,7 @@
1
1
  source 'https://rubygems.org'
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
- gem 'oauth', "~> 0.4.4"
6
- gem 'oauth2', "~> 0.8.0"
7
- gem 'bcrypt-ruby', "~> 3.0.0"
8
2
 
9
- # Add dependencies to develop your gem here.
10
- # Include everything needed to run rake, tests, features, etc.
11
-
12
- gem 'abstract', '>= 1.0.0'
13
- gem "rails", "~> 3.2.15"
14
- gem 'json', ">= 1.7.7"
15
- gem "rspec", "~> 2.14.0"
16
- gem 'rspec-rails', "~> 2.14.0"
3
+ gem 'rails', '~> 3.2'
17
4
  gem 'sqlite3'
18
- gem "yard", "~> 0.6.0"
19
- gem "bundler", ">= 1.1.0"
20
- gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
21
- gem 'timecop'
22
5
 
23
6
  group :mongomapper do
24
7
  gem 'mongo_mapper'
@@ -28,3 +11,11 @@ group :mongoid do
28
11
  gem 'mongoid', "~> 2.4.4"
29
12
  gem 'bson_ext'
30
13
  end
14
+
15
+ group :datamapper do
16
+ gem 'mysql2'
17
+ gem 'data_mapper'
18
+ gem 'dm-mysql-adapter'
19
+ end
20
+
21
+ gemspec
@@ -1,16 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'oauth', "~> 0.4.4"
4
- gem 'oauth2', "~> 0.8.0"
5
- gem 'bcrypt-ruby', "~> 3.0.0"
6
-
7
- gem "rspec", "~> 2.14.0"
8
- gem 'rspec-rails', "~> 2.14.0"
9
- #gem 'ruby-debug19'
10
3
  gem 'sqlite3'
11
- gem "yard", "~> 0.6.0"
12
- gem "bundler", ">= 1.1.0"
13
- gem 'timecop'
14
4
 
15
5
  group :mongomapper do
16
6
  gem 'mongo_mapper', github: 'jnunemaker/mongomapper'
@@ -21,4 +11,12 @@ group :mongoid do
21
11
  gem 'bson_ext'
22
12
  end
23
13
 
14
+ group :datamapper do
15
+ gem 'mysql2'
16
+ gem 'data_mapper'
17
+ gem 'dm-mysql-adapter'
18
+ end
19
+
24
20
  gem 'rails', '~> 4.0.1'
21
+
22
+ gemspec
data/README.md CHANGED
@@ -1,19 +1,17 @@
1
- [<img src="https://secure.travis-ci.org/NoamB/sorcery.png"
2
- />](http://travis-ci.org/NoamB/sorcery) [<img
3
- src="https://codeclimate.com/github/NoamB/sorcery.png"
4
- />](https://codeclimate.com/github/NoamB/sorcery)
1
+ [![Build Status](https://travis-ci.org/NoamB/sorcery.svg?branch=master)](https://travis-ci.org/NoamB/sorcery)
2
+ [![Code Climate](https://codeclimate.com/github/NoamB/sorcery.png)](https://codeclimate.com/github/NoamB/sorcery)
5
3
 
6
4
  # sorcery
7
- Magical Authentication for Rails 3 and 4. Supports ActiveRecord, Mongoid and
8
- MongoMapper.
5
+ Magical Authentication for Rails 3 and 4. Supports ActiveRecord,
6
+ DataMapper, Mongoid and MongoMapper.
9
7
 
10
8
  Inspired by restful_authentication, Authlogic and Devise. Crypto code taken
11
9
  almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan
12
10
  Bates's railscasts about it.
13
11
 
14
- **Rails 4 status:** basicly it works without issues, except
15
- [the issue with protect_from_forgery](https://github.com/NoamB/sorcery/issues/464).
16
- We will release new version soon, which will be updated for Rails 4.
12
+ **Rails 4 status:** [Sorcery 0.8.5](http://rubygems.org/gems/sorcery/versions/0.8.5) is fully tested and ready for Rails 4.0.
13
+
14
+ **Rails 4.1 status:** Sorcery 0.8.6 (to be released, currently in master branch) works with Rails 4.1
17
15
 
18
16
  https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication
19
17
 
@@ -212,7 +210,8 @@ Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
212
210
 
213
211
 
214
212
  External (see lib/sorcery/controller/submodules/external.rb):
215
- * OAuth1 and OAuth2 support (currently twitter & facebook)
213
+ * OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google,
214
+ LinkedIn, VK, LiveID and Xing)
216
215
  * configurable db field names and authentications table.
217
216
 
218
217
 
@@ -243,17 +242,38 @@ In short, an app that works with x.3.1 should be able to upgrade to x.3.2 with
243
242
  no code changes. The same cannot be said about upgrading to x.4.0 and above,
244
243
  however.
245
244
 
245
+ ## DataMapper Support
246
+
247
+ Important notes:
248
+
249
+ * Expected to work with DM adapters: dm-mysql-adapter,
250
+ dm-redis-adapter.
251
+ * Submodules DM adapter dependent: activity_logging (dm-mysql-adapter)
252
+ * Usage: include DataMapper::Resource in user model, follow sorcery
253
+ instructions (remember to add property id, validators and accessor
254
+ attributes such as password and password_confirmation)
255
+ * Option downcase__username_before_authenticating and dm-mysql,
256
+ http://datamapper.lighthouseapp.com/projects/20609/tickets/1105-add-support-for-definingchanging-default-collation
257
+
246
258
  ## Upgrading
247
259
 
248
260
  Important notes while upgrading:
249
261
 
262
+ * If you are upgrading from <= **0.8.5** and you're using Sorcery test helpers,
263
+ you need to change the way you include them to following code:
264
+
265
+ RSpec.configure do |config|
266
+ config.include Sorcery::TestHelpers::Rails::Controler, type: [:controller]
267
+ config.include Sorcery::TestHelpers::Rails::Integration, type: [:feature]
268
+ end
269
+
250
270
  * If are upgrading to **0.8.2** and use activity_logging feature with
251
271
  ActiveRecord, you will have to add a new column
252
272
  `last_login_from_ip_address`
253
273
  [#465](https://github.com/NoamB/sorcery/issues/465)
254
274
  * Sinatra support existed until **v0.7.0** (including), but was dropped
255
275
  later due to being a maintenance nightmare.
256
- * If upgrading from <= **0.6.1 to >= <b>0.7.0** you need to change
276
+ * If upgrading from <= **0.6.1 to >= **0.7.0** you need to change
257
277
  'username_attribute_name' to 'username_attribute_names' in initializer.
258
278
  * If upgrading from <= **v0.5.1** to >= **v0.5.2** you need to explicitly
259
279
  set your user_class model in the initializer file.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.2
1
+ 0.8.5
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'sqlite3'
4
+ gem 'rails', '~> 4.1'
5
+
6
+ gemspec path: '..'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.0'
4
+
5
+ gem 'mongo_mapper', github: 'mongomapper/mongomapper'
6
+ gem 'sqlite3'
7
+
8
+ gemspec path: '..'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 4.1.0'
4
+
5
+ gem 'pry'
6
+
7
+ gem 'mongoid', github: 'mongoid/mongoid'
8
+ gem 'bson_ext'
9
+ gem 'sqlite3'
10
+
11
+ gemspec path: '..'
@@ -6,6 +6,7 @@ module Sorcery
6
6
  autoload :ActiveRecord, 'sorcery/model/adapters/active_record'
7
7
  autoload :Mongoid, 'sorcery/model/adapters/mongoid'
8
8
  autoload :MongoMapper, 'sorcery/model/adapters/mongo_mapper'
9
+ autoload :DataMapper, 'sorcery/model/adapters/datamapper'
9
10
  end
10
11
  module Submodules
11
12
  autoload :UserActivation, 'sorcery/model/submodules/user_activation'
@@ -25,25 +26,12 @@ module Sorcery
25
26
  autoload :HttpBasicAuth, 'sorcery/controller/submodules/http_basic_auth'
26
27
  autoload :ActivityLogging, 'sorcery/controller/submodules/activity_logging'
27
28
  autoload :External, 'sorcery/controller/submodules/external'
28
- module External
29
- module Protocols
30
- autoload :Oauth1, 'sorcery/controller/submodules/external/protocols/oauth1'
31
- autoload :Oauth2, 'sorcery/controller/submodules/external/protocols/oauth2'
32
- end
33
- module Providers
34
- autoload :Base, 'sorcery/controller/submodules/external/providers/base'
35
- autoload :Twitter, 'sorcery/controller/submodules/external/providers/twitter'
36
- autoload :Facebook, 'sorcery/controller/submodules/external/providers/facebook'
37
- autoload :Github, 'sorcery/controller/submodules/external/providers/github'
38
- autoload :Google, 'sorcery/controller/submodules/external/providers/google'
39
- autoload :Liveid, 'sorcery/controller/submodules/external/providers/liveid'
40
- autoload :Linkedin, 'sorcery/controller/submodules/external/providers/linkedin'
41
- autoload :Vk, 'sorcery/controller/submodules/external/providers/vk'
42
- autoload :Xing, 'sorcery/controller/submodules/external/providers/xing'
43
- end
44
- end
45
29
  end
46
30
  end
31
+ module Protocols
32
+ autoload :Oauth, 'sorcery/protocols/oauth'
33
+ autoload :Oauth2, 'sorcery/protocols/oauth2'
34
+ end
47
35
  module CryptoProviders
48
36
  autoload :Common, 'sorcery/crypto_providers/common'
49
37
  autoload :AES256, 'sorcery/crypto_providers/aes256'
@@ -53,34 +41,38 @@ module Sorcery
53
41
  autoload :SHA256, 'sorcery/crypto_providers/sha256'
54
42
  autoload :SHA512, 'sorcery/crypto_providers/sha512'
55
43
  end
56
- autoload :TestHelpers, 'sorcery/test_helpers'
57
44
  module TestHelpers
58
- autoload :Rails, 'sorcery/test_helpers/rails'
59
45
  autoload :Internal, 'sorcery/test_helpers/internal'
60
46
  module Internal
61
47
  autoload :Rails, 'sorcery/test_helpers/internal/rails'
62
48
  end
49
+ autoload :Rails, 'sorcery/test_helpers/rails'
50
+ module Rails
51
+ autoload :Controller, 'sorcery/test_helpers/rails/controller'
52
+ autoload :Integration, 'sorcery/test_helpers/rails/integration'
53
+ end
63
54
 
64
55
  end
65
56
 
66
57
  if defined?(ActiveRecord)
67
- ActiveRecord::Base.send(:include, Sorcery::Model)
68
- ActiveRecord::Base.send(:include, Sorcery::Model::Adapters::ActiveRecord)
58
+ ActiveRecord::Base.extend Sorcery::Model
59
+ ActiveRecord::Base.send :include, Sorcery::Model::Adapters::ActiveRecord
69
60
  end
70
61
 
71
62
  if defined?(Mongoid)
72
- Mongoid::Document.module_eval do
73
- included do
74
- attr_reader :new_record
75
- include Sorcery::Model
76
- include Sorcery::Model::Adapters::Mongoid
77
- end
78
- end
63
+ Mongoid::Document::ClassMethods.send :include, Sorcery::Model
64
+ Mongoid::Document::ClassMethods.send :include, Sorcery::Model::Adapters::Mongoid::ClassMethods
65
+ Mongoid::Document.send :include, Sorcery::Model::Adapters::Mongoid::InstanceMethods
79
66
  end
80
67
 
81
68
  if defined?(MongoMapper)
82
69
  MongoMapper::Document.send(:plugin, Sorcery::Model::Adapters::MongoMapper)
83
70
  end
84
71
 
72
+ if defined?(DataMapper)
73
+ DataMapper::Model.append_extensions(Sorcery::Model)
74
+ DataMapper::Model.append_inclusions(Sorcery::Model::Adapters::DataMapper)
75
+ end
76
+
85
77
  require 'sorcery/engine' if defined?(Rails) && Rails::VERSION::MAJOR >= 3
86
78
  end
@@ -5,7 +5,7 @@ module Sorcery
5
5
  include InstanceMethods
6
6
  Config.submodules.each do |mod|
7
7
  begin
8
- include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
8
+ include Submodules.const_get(mod.to_s.split('_').map { |p| p.capitalize }.join)
9
9
  rescue NameError
10
10
  # don't stop on a missing submodule.
11
11
  end
@@ -72,13 +72,12 @@ module Sorcery
72
72
  end
73
73
 
74
74
  # attempts to auto-login from the sources defined (session, basic_auth, cookie, etc.)
75
- # returns the logged in user if found, false if not (using old restful-authentication trick, nil != false).
75
+ # returns the logged in user if found, nil if not
76
76
  def current_user
77
- if @current_user == false
78
- false
79
- else
80
- @current_user ||= login_from_session || login_from_other_sources
77
+ unless defined?(@current_user)
78
+ @current_user = login_from_session || login_from_other_sources || nil
81
79
  end
80
+ @current_user
82
81
  end
83
82
 
84
83
  def current_user=(user)
@@ -127,11 +126,7 @@ module Sorcery
127
126
  end
128
127
 
129
128
  def login_from_session
130
- @current_user = (user_class.find(session[:user_id]) if session[:user_id]) || false
131
- rescue => exception
132
- return false if defined?(Mongoid) and exception.is_a?(Mongoid::Errors::DocumentNotFound)
133
- return false if defined?(ActiveRecord) and exception.is_a?(ActiveRecord::RecordNotFound)
134
- raise exception
129
+ @current_user = (user_class.find_by_id(session[:user_id]) if session[:user_id]) || nil
135
130
  end
136
131
 
137
132
  def after_login!(user, credentials = [])
@@ -6,21 +6,38 @@ module Sorcery
6
6
  module External
7
7
  def self.included(base)
8
8
  base.send(:include, InstanceMethods)
9
+
10
+ require 'sorcery/providers/base'
11
+ require 'sorcery/providers/facebook'
12
+ require 'sorcery/providers/twitter'
13
+ require 'sorcery/providers/vk'
14
+ require 'sorcery/providers/linkedin'
15
+ require 'sorcery/providers/liveid'
16
+ require 'sorcery/providers/xing'
17
+ require 'sorcery/providers/github'
18
+ require 'sorcery/providers/google'
19
+
9
20
  Config.module_eval do
10
21
  class << self
11
- attr_reader :external_providers # external providers like twitter.
12
- attr_accessor :ca_file # path to ca_file. By default use a internal ca-bundle.crt.
13
-
14
- def merge_external_defaults!
15
- @defaults.merge!(:@external_providers => [],
16
- :@ca_file => File.join(File.expand_path(File.dirname(__FILE__)), 'external/protocols/certs/ca-bundle.crt'))
17
- end
22
+ attr_reader :external_providers
23
+ attr_accessor :ca_file
18
24
 
19
25
  def external_providers=(providers)
20
- providers.each do |provider|
21
- include Providers.const_get(provider.to_s.split("_").map {|p| p.capitalize}.join(""))
26
+ @external_providers = providers
27
+
28
+ providers.each do |name|
29
+ class_eval <<-E
30
+ def self.#{name}
31
+ @#{name} ||= Sorcery::Providers.const_get('#{name}'.to_s.capitalize).new
32
+ end
33
+ E
22
34
  end
23
35
  end
36
+
37
+ def merge_external_defaults!
38
+ @defaults.merge!(:@external_providers => [],
39
+ :@ca_file => File.join(File.expand_path(File.dirname(__FILE__)), '../../protocols/certs/ca-bundle.crt'))
40
+ end
24
41
  end
25
42
  merge_external_defaults!
26
43
  end
@@ -31,9 +48,7 @@ module Sorcery
31
48
 
32
49
  # save the singleton ProviderClient instance into @provider
33
50
  def sorcery_get_provider(provider_name)
34
- allowed = %w(facebook github google linkedin liveid twitter vk xing)
35
- return unless allowed.include?(provider_name.to_s)
36
-
51
+ return unless Config.external_providers.include?(provider_name.to_sym)
37
52
  Config.send(provider_name.to_sym)
38
53
  end
39
54
 
@@ -121,7 +136,7 @@ module Sorcery
121
136
  # first check to see if user has a particular authentication already
122
137
  unless (current_user.send(config.authentications_class.name.underscore.pluralize).send("find_by_#{config.provider_attribute_name}_and_#{config.provider_uid_attribute_name}", provider_name, @user_hash[:uid].to_s))
123
138
  user = current_user.send(config.authentications_class.name.underscore.pluralize).build(config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name.to_s)
124
- user.save(:validate => false)
139
+ user.sorcery_save(:validate => false)
125
140
  else
126
141
  user = false
127
142
  end
@@ -144,7 +159,7 @@ module Sorcery
144
159
  session[:incomplete_user] = {
145
160
  :provider => {config.provider_uid_attribute_name => @user_hash[:uid], config.provider_attribute_name => provider_name},
146
161
  :user_hash => attrs
147
- } unless user.save
162
+ } unless user.sorcery_save
148
163
 
149
164
  return user
150
165
  end
@@ -181,7 +196,7 @@ module Sorcery
181
196
  return false unless yield @user
182
197
  end
183
198
 
184
- @user.save(:validate => false)
199
+ @user.sorcery_save(:validate => false)
185
200
  user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider_name, config.provider_uid_attribute_name => @user_hash[:uid]})
186
201
  end
187
202
  @user