sorcery 0.9.1 → 0.10.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -272
  6. data/Rakefile +2 -2
  7. data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
  8. data/lib/generators/sorcery/helpers.rb +4 -4
  9. data/lib/generators/sorcery/install_generator.rb +25 -19
  10. data/lib/generators/sorcery/templates/initializer.rb +27 -52
  11. data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
  12. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/core.rb +3 -3
  14. data/lib/generators/sorcery/templates/migration/external.rb +2 -2
  15. data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
  16. data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
  17. data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
  18. data/lib/sorcery.rb +0 -28
  19. data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
  20. data/lib/sorcery/controller.rb +19 -21
  21. data/lib/sorcery/controller/config.rb +20 -18
  22. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  23. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  24. data/lib/sorcery/controller/submodules/external.rb +22 -14
  25. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  26. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  27. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  28. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  29. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  30. data/lib/sorcery/crypto_providers/common.rb +1 -1
  31. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  33. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  34. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  35. data/lib/sorcery/engine.rb +3 -8
  36. data/lib/sorcery/model.rb +24 -32
  37. data/lib/sorcery/model/config.rb +64 -49
  38. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  39. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  40. data/lib/sorcery/model/submodules/external.rb +3 -7
  41. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  42. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  43. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  44. data/lib/sorcery/model/temporary_token.rb +2 -2
  45. data/lib/sorcery/protocols/oauth.rb +3 -9
  46. data/lib/sorcery/protocols/oauth2.rb +0 -2
  47. data/lib/sorcery/providers/base.rb +4 -4
  48. data/lib/sorcery/providers/facebook.rb +5 -8
  49. data/lib/sorcery/providers/github.rb +5 -7
  50. data/lib/sorcery/providers/google.rb +3 -5
  51. data/lib/sorcery/providers/heroku.rb +6 -8
  52. data/lib/sorcery/providers/jira.rb +12 -17
  53. data/lib/sorcery/providers/linkedin.rb +6 -8
  54. data/lib/sorcery/providers/liveid.rb +4 -7
  55. data/lib/sorcery/providers/paypal.rb +60 -0
  56. data/lib/sorcery/providers/salesforce.rb +3 -5
  57. data/lib/sorcery/providers/slack.rb +45 -0
  58. data/lib/sorcery/providers/twitter.rb +4 -6
  59. data/lib/sorcery/providers/vk.rb +3 -5
  60. data/lib/sorcery/providers/wechat.rb +79 -0
  61. data/lib/sorcery/providers/xing.rb +7 -10
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  64. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  65. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  66. data/lib/sorcery/version.rb +1 -1
  67. data/sorcery.gemspec +25 -27
  68. data/spec/active_record/user_activation_spec.rb +2 -3
  69. data/spec/active_record/user_activity_logging_spec.rb +2 -4
  70. data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
  71. data/spec/active_record/user_oauth_spec.rb +3 -4
  72. data/spec/active_record/user_remember_me_spec.rb +3 -4
  73. data/spec/active_record/user_reset_password_spec.rb +2 -3
  74. data/spec/active_record/user_spec.rb +7 -7
  75. data/spec/controllers/controller_activity_logging_spec.rb +13 -24
  76. data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
  77. data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
  78. data/spec/controllers/controller_oauth2_spec.rb +125 -100
  79. data/spec/controllers/controller_oauth_spec.rb +86 -66
  80. data/spec/controllers/controller_remember_me_spec.rb +35 -30
  81. data/spec/controllers/controller_session_timeout_spec.rb +14 -15
  82. data/spec/controllers/controller_spec.rb +77 -111
  83. data/spec/orm/active_record.rb +1 -1
  84. data/spec/rails_app/app/active_record/authentication.rb +1 -1
  85. data/spec/rails_app/app/active_record/user.rb +2 -2
  86. data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
  87. data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
  88. data/spec/rails_app/config.ru +1 -1
  89. data/spec/rails_app/config/application.rb +7 -7
  90. data/spec/rails_app/config/boot.rb +1 -1
  91. data/spec/rails_app/config/environments/test.rb +1 -1
  92. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  93. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  94. data/spec/rails_app/config/routes.rb +11 -1
  95. data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
  96. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
  97. data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
  98. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
  99. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
  100. data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
  101. data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
  102. data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
  103. data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
  104. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
  105. data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
  106. data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
  107. data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
  108. data/spec/shared_examples/user_shared_examples.rb +215 -118
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -83
  112. data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
  113. data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
  114. data/gemfiles/mongoid-rails41.gemfile +0 -9
  115. data/gemfiles/mongoid3-rails32.gemfile +0 -9
  116. data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
  117. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
  118. data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
  119. data/lib/sorcery/railties/tasks.rake +0 -6
  120. data/spec/data_mapper/user_activation_spec.rb +0 -10
  121. data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
  122. data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
  123. data/spec/data_mapper/user_oauth_spec.rb +0 -9
  124. data/spec/data_mapper/user_remember_me_spec.rb +0 -8
  125. data/spec/data_mapper/user_reset_password_spec.rb +0 -8
  126. data/spec/data_mapper/user_spec.rb +0 -27
  127. data/spec/mongo_mapper/user_activation_spec.rb +0 -9
  128. data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
  129. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
  130. data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
  131. data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
  132. data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
  133. data/spec/mongo_mapper/user_spec.rb +0 -37
  134. data/spec/mongoid/user_activation_spec.rb +0 -9
  135. data/spec/mongoid/user_activity_logging_spec.rb +0 -8
  136. data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
  137. data/spec/mongoid/user_oauth_spec.rb +0 -8
  138. data/spec/mongoid/user_remember_me_spec.rb +0 -8
  139. data/spec/mongoid/user_reset_password_spec.rb +0 -8
  140. data/spec/mongoid/user_spec.rb +0 -51
  141. data/spec/orm/data_mapper.rb +0 -48
  142. data/spec/orm/mongo_mapper.rb +0 -10
  143. data/spec/orm/mongoid.rb +0 -22
  144. data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
  145. data/spec/rails_app/app/data_mapper/user.rb +0 -7
  146. data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
  147. data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
  148. data/spec/rails_app/app/mongoid/authentication.rb +0 -7
  149. data/spec/rails_app/app/mongoid/user.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c0e37f33ed4fa3e085ccc8e3a6a5526afb632f2
4
- data.tar.gz: 1b224ad20e8ed01e04a2b7a25153e5949b56fa4f
3
+ metadata.gz: bb39af475e80d1cf60b3d9d29d594596e1e49f7b
4
+ data.tar.gz: 4c673dbd8669efa22e8422a8d6991100e6ffdd15
5
5
  SHA512:
6
- metadata.gz: 48d1dd07a9ab99ade78c490bfffd27144b3951d5ba1f45bcfc1baede6db4cbe228e8916025bfd69fbc48d3342724b00ac2cfd9ecc41110d1b9fdd9559885091b
7
- data.tar.gz: 250ceb737b38dab40dd3e16488f3e37aadf2b09fe94c6147ed92a2d42aab2d61d01601b3a2891403f70cc23ef4e675f4fb1ad83072d59ee71d8d6e5fd9d9c20d
6
+ metadata.gz: 259226a4a2577089ad0f2ff0a4f2db786c2b0b035ac62d942788e37dcac483e3843c4847e9dda3ffddab601ad981d46a809461da091779fb914497f80e9a92ef
7
+ data.tar.gz: 0d8d54eb5b6f600d17e28b78124ee046c7d00addbcf349d47de742dc1e3abbd2f4b8ed6ce2766f5f98037b0634324554eb389fccc3bde348d27ea1c021a5b378
@@ -1,132 +1,57 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
3
+ - jruby
4
4
  - 2.0.0
5
- - 2.1
5
+ - 2.1.10
6
+ - 2.2.6
7
+ - 2.3.3
8
+ - 2.4.0
6
9
 
7
- services: mongodb
10
+ env:
11
+ global:
12
+ - JRUBY_OPTS="--2.0"
8
13
 
9
14
  gemfile:
10
15
  - Gemfile
11
-
12
- env:
13
- - "SORCERY_ORM=active_record"
14
- - "SORCERY_ORM=mongoid"
15
- - "SORCERY_ORM=mongo_mapper"
16
- - "SORCERY_ORM=data_mapper"
16
+ - gemfiles/active_record-rails40.gemfile
17
+ - gemfiles/active_record-rails41.gemfile
18
+ - gemfiles/active_record-rails42.gemfile
17
19
 
18
20
  before_script:
19
21
  - mysql -e 'create database sorcery_test;'
20
22
 
23
+ before_install:
24
+ - rvm get stable --auto-dotfiles
25
+ - gem update bundler
26
+
21
27
  matrix:
22
28
  allow_failures:
23
- - rvm: :jruby
24
-
25
- include:
26
- - rvm: 1.9.3
27
- gemfile: gemfiles/mongoid-rails41.gemfile
28
- env: "SORCERY_ORM=mongoid"
29
-
30
- - rvm: 2.0.0
31
- gemfile: gemfiles/mongoid-rails41.gemfile
32
- env: "SORCERY_ORM=mongoid"
33
-
34
- - rvm: 2.1
35
- gemfile: gemfiles/mongoid-rails41.gemfile
36
- env: "SORCERY_ORM=mongoid"
37
-
38
29
  - rvm: jruby
39
- gemfile: gemfiles/mongoid-rails41.gemfile
40
- env: "SORCERY_ORM=mongoid"
41
-
42
- - rvm: 1.9.3
43
- gemfile: gemfiles/mongo_mapper-rails41.gemfile
44
- env: "SORCERY_ORM=mongo_mapper"
45
30
 
31
+ exclude:
46
32
  - rvm: 2.0.0
47
- gemfile: gemfiles/mongo_mapper-rails41.gemfile
48
- env: "SORCERY_ORM=mongo_mapper"
49
-
50
- - rvm: 2.1
51
- gemfile: gemfiles/mongo_mapper-rails41.gemfile
52
- env: "SORCERY_ORM=mongo_mapper"
53
-
54
- - rvm: jruby
55
- gemfile: gemfiles/mongo_mapper-rails41.gemfile
56
- env: "SORCERY_ORM=mongo_mapper"
57
-
58
- - rvm: 1.9.3
59
- gemfile: gemfiles/active_record-rails41.gemfile
60
- env: "SORCERY_ORM=active_record"
33
+ gemfile: gemfiles/active_record-rails42.gemfile
61
34
 
62
35
  - rvm: 2.0.0
63
- gemfile: gemfiles/active_record-rails41.gemfile
64
- env: "SORCERY_ORM=active_record"
65
-
66
- - rvm: 2.1
67
- gemfile: gemfiles/active_record-rails41.gemfile
68
- env: "SORCERY_ORM=active_record"
36
+ gemfile: Gemfile
69
37
 
70
- - rvm: jruby
71
- gemfile: gemfiles/active_record-rails41.gemfile
72
- env: "SORCERY_ORM=active_record"
38
+ - rvm: 2.1.10
39
+ gemfile: Gemfile
73
40
 
74
- - rvm: 1.9.3
75
- gemfile: gemfiles/mongoid-rails40.gemfile
76
- env: "SORCERY_ORM=mongoid"
77
-
78
- - rvm: 2.0.0
79
- gemfile: gemfiles/mongoid-rails40.gemfile
80
- env: "SORCERY_ORM=mongoid"
81
-
82
- - rvm: 2.1
83
- gemfile: gemfiles/mongoid-rails40.gemfile
84
- env: "SORCERY_ORM=mongoid"
85
-
86
- - rvm: jruby
87
- gemfile: gemfiles/mongoid-rails40.gemfile
88
- env: "SORCERY_ORM=mongoid"
89
-
90
- - rvm: 1.9.3
91
- gemfile: gemfiles/mongo_mapper-rails40.gemfile
92
- env: "SORCERY_ORM=mongo_mapper"
93
-
94
- - rvm: 2.0.0
95
- gemfile: gemfiles/mongo_mapper-rails40.gemfile
96
- env: "SORCERY_ORM=mongo_mapper"
97
-
98
- - rvm: 2.1
99
- gemfile: gemfiles/mongo_mapper-rails40.gemfile
100
- env: "SORCERY_ORM=mongo_mapper"
101
-
102
- - rvm: jruby
103
- gemfile: gemfiles/mongo_mapper-rails40.gemfile
104
- env: "SORCERY_ORM=mongo_mapper"
105
-
106
- - rvm: 1.9.3
41
+ - rvm: 2.2.6
107
42
  gemfile: gemfiles/active_record-rails40.gemfile
108
- env: "SORCERY_ORM=active_record"
109
43
 
110
- - rvm: 2.0.0
44
+ - rvm: 2.3.3
111
45
  gemfile: gemfiles/active_record-rails40.gemfile
112
- env: "SORCERY_ORM=active_record"
113
46
 
114
- - rvm: 2.1
47
+ - rvm: 2.4.0
115
48
  gemfile: gemfiles/active_record-rails40.gemfile
116
- env: "SORCERY_ORM=active_record"
117
49
 
118
- - rvm: jruby
119
- gemfile: gemfiles/active_record-rails40.gemfile
120
- env: "SORCERY_ORM=active_record"
121
-
122
- - rvm: 1.9.3
123
- gemfile: gemfiles/mongoid3-rails32.gemfile
124
- env: "SORCERY_ORM=mongoid"
50
+ - rvm: 2.4.0
51
+ gemfile: gemfiles/active_record-rails41.gemfile
125
52
 
126
- - rvm: 2.0.0
127
- gemfile: gemfiles/mongoid3-rails32.gemfile
128
- env: "SORCERY_ORM=mongoid"
53
+ - rvm: 2.4.0
54
+ gemfile: gemfiles/active_record-rails42.gemfile
129
55
 
130
- - rvm: 2.1
131
- gemfile: gemfiles/mongoid3-rails32.gemfile
132
- env: "SORCERY_ORM=mongoid"
56
+ - rvm: jruby
57
+ gemfile: Gemfile
@@ -1,8 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## 1.0 (not released yet)
3
+ ## 0.10.0
4
4
 
5
5
  * Adapters (Mongoid, MongoMapper, DataMapper) are now separated from the core Sorcery repo and moved under `sorcery-rails` organization. Special thanks to @juike!
6
+ * `current_users` method was removed
7
+ * Added `logged_in?` `logged_out?` `online?` to activity_logging instance methods
8
+ * Added support for PayPal OAuth (thanks to @rubenmoya)
9
+ * Added support for Slack OAuth (thanks to @youzik)
10
+ * Added support for WeChat OAuth (thanks to @Darmody)
11
+ * Deprecated Rails 3
12
+ * Deprecated using `callback_filter` in favor of `callback_action`
13
+ * Added null: false to migrations
14
+ * Added support for Rails 5 (thanks to @kyuden)
15
+ * Added support for Ruby 2.4 (thanks to @kyuden)
16
+ * Added WeChat provider to external submodule.
17
+ * Namespace login lock/unlock methods to fix conflicts with Rails lock/unlock (thanks to @kyuden)
6
18
 
7
19
  ## 0.9.1
8
20
 
data/Gemfile CHANGED
@@ -1,22 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'rails', '~> 3.2'
3
+ gem 'rails', '~> 5.0.0'
4
+ gem 'rails-controller-testing'
4
5
  gem 'sqlite3'
5
6
  gem 'pry'
6
7
 
7
- group :mongomapper do
8
- gem 'mongo_mapper'
9
- end
10
-
11
- group :mongoid do
12
- gem 'mongoid', "~> 2.4.4"
13
- gem 'bson_ext'
14
- end
15
-
16
- group :datamapper do
17
- gem 'mysql2'
18
- gem 'data_mapper'
19
- gem 'dm-mysql-adapter'
20
- end
21
-
22
8
  gemspec
data/README.md CHANGED
@@ -1,96 +1,96 @@
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)
3
- [![Inline docs](http://inch-ci.org/github/NoamB/sorcery.png?branch=master)](http://inch-ci.org/github/NoamB/sorcery)
1
+ # Sorcery: Magical Authentication
4
2
 
5
- # sorcery
6
- Magical Authentication for Rails 3 and 4. Supports ActiveRecord,
7
- DataMapper, Mongoid and MongoMapper.
3
+ [![Gem Version](https://badge.fury.io/rb/sorcery.svg)](https://rubygems.org/gems/sorcery)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/sorcery.svg)](https://rubygems.org/gems/sorcery)
5
+ [![Build Status](https://travis-ci.org/Sorcery/sorcery.svg?branch=master)](https://travis-ci.org/Sorcery/sorcery)
6
+ [![Code Climate](https://codeclimate.com/github/Sorcery/sorcery.svg)](https://codeclimate.com/github/Sorcery/sorcery)
7
+ [![Inline docs](http://inch-ci.org/github/Sorcery/sorcery.svg?branch=master)](http://inch-ci.org/github/Sorcery/sorcery)
8
+ [![Join the chat at https://gitter.im/Sorcery/sorcery](https://badges.gitter.im/join_chat.svg)](https://gitter.im/Sorcery/sorcery?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
9
 
9
- Inspired by restful_authentication, Authlogic and Devise. Crypto code taken
10
- almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan
11
- Bates's railscasts about it.
10
+ Magical Authentication for Rails. Supports ActiveRecord, DataMapper, Mongoid and MongoMapper.
12
11
 
13
- **What's happening now?** We are working on 1.0 version, which will include some API-breaking changes. It should be released about April 2015.
14
- Until then we'll continue releasing `0.9.x` version with bug fixed.
12
+ Inspired by Restful Authentication, Authlogic and Devise. Crypto code taken almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan Bates's Railscast about it.
15
13
 
16
- **Rails 4 status:** [Sorcery 0.9.0](http://rubygems.org/gems/sorcery/versions/0.9.0) is fully tested and ready for Rails 4.0, 4.1 and 4.2.
17
- **Mongoid status:** Version 0.9.0 works with Mongoid 4.
14
+ ### Philosophy
18
15
 
19
- https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication
16
+ Sorcery is a stripped-down, bare-bones authentication library, with which you can write your own authentication flow. It was built with a few goals in mind:
20
17
 
21
- ## Philosophy
22
-
23
- Sorcery is a stripped-down, bare-bones authentication library, with which you
24
- can write your own authentication flow. It was built with a few goals in mind:
25
-
26
- * Less is more - less than 20 public methods to remember for the entire
27
- feature-set make the lib easy to 'get'.
28
- * No built-in or generated code - use the library's methods inside *your
29
- own* MVC structures, and don't fight to fix someone else's.
30
- * Magic yes, Voodoo no - the lib should be easy to hack for most developers.
31
- * Configuration over Confusion - Centralized (1 file), Simple & short
32
- configuration as possible, not drowning in syntactic sugar.
33
- * Keep MVC cleanly separated - DB is for models, sessions are for
34
- controllers. Models stay unaware of sessions.
35
-
36
-
37
- Hopefully, I've achieved this. If not, let me know.
18
+ - Less is more - less than 20 public methods to remember for the entire feature-set make the lib easy to 'get'.
19
+ - No built-in or generated code - use the library's methods inside *your own* MVC structures, and don't fight to fix someone else's.
20
+ - Magic yes, Voodoo no - the lib should be easy to hack for most developers.
21
+ - Configuration over Confusion - Centralized (1 file), Simple & short configuration as possible, not drowning in syntactic sugar.
22
+ - Keep MVC cleanly separated - DB is for models, sessions are for controllers. Models stay unaware of sessions.
38
23
 
39
24
  ## Useful Links
40
25
 
41
- [Documentation](http://rubydoc.info/gems/sorcery) |
42
- [Railscast](http://railscasts.com/episodes/283-authentication-with-sorcery) | [Simple tutorial](https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication) | [Example Rails 3 app](https://github.com/NoamB/sorcery-example-app)
26
+ - [Documentation](http://rubydoc.info/gems/sorcery)
27
+ - [Railscast](http://railscasts.com/episodes/283-authentication-with-sorcery)
28
+ - [Simple tutorial](https://github.com/Sorcery/sorcery/wiki/Simple-Password-Authentication)
29
+ - [Example Rails app](https://github.com/Sorcery/sorcery-example-app)
43
30
 
44
- Check out the tutorials in the [Wiki](https://github.com/NoamB/sorcery/wiki) for more!
31
+ Check out the tutorials in the [wiki](https://github.com/Sorcery/sorcery/wiki) for more:
32
+
33
+ - [DataMapper Support](https://github.com/Sorcery/sorcery/wiki/DataMapper-Support)
34
+ - [DelayedJob Integration](https://github.com/Sorcery/sorcery/wiki/DelayedJob-Integration)
35
+ - [Simple Password Authentication](https://github.com/Sorcery/sorcery/wiki/Simple-Password-Authentication)
36
+ - [Single Table Inheritance Support](https://github.com/Sorcery/sorcery/wiki/Single-Table-Inheritance-Support)
37
+ - [Upgrading](https://github.com/Sorcery/sorcery/wiki/Upgrading)
45
38
 
46
39
  ## API Summary
47
40
 
48
41
  Below is a summary of the library methods. Most method names are self
49
42
  explaining and the rest are commented:
50
43
 
44
+ ### Core
51
45
 
52
- ### core
53
46
  ```ruby
54
- require_login # this is a before filter
47
+ require_login # This is a before action
55
48
  login(email, password, remember_me = false)
56
- auto_login(user)# login without credentials
49
+ auto_login(user) # Login without credentials
57
50
  logout
58
- logged_in? # available to view
59
- current_user # available to view
60
- redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
61
- @user.external? # external users, such as facebook/twitter etc.
62
- @user.active_for_authentication? # add this method to define behaviour that will prevent selected users from signing in
51
+ logged_in? # Available in views
52
+ current_user # Available in views
53
+ redirect_back_or_to # Use when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted
54
+ @user.external? # Users who signed up using Facebook, Twitter, etc.
55
+ @user.active_for_authentication? # Add this method to define behaviour that will prevent selected users from signing in
56
+ @user.valid_password?('secret') # Compares 'secret' with the actual user's password, returns true if they match
63
57
  User.authenticates_with_sorcery!
64
58
  ```
65
59
 
66
- ### http basic auth
60
+ ### HTTP Basic Auth
61
+
67
62
  ```ruby
68
- require_login_from_http_basic # this is a before filter
63
+ require_login_from_http_basic # This is a before action
69
64
  ```
70
65
 
71
- ### external
66
+ ### External
67
+
72
68
  ```ruby
73
- login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
74
- login_from(provider) # tries to login from the external provider's callback.
75
- create_from(provider) # create the user in the local app db.
69
+ login_at(provider) # Sends the user to an external service (Facebook, Twitter, etc.) to authenticate
70
+ login_from(provider) # Tries to login from the external provider's callback
71
+ create_from(provider) # Create the user in the local app database
76
72
  ```
77
73
 
78
- ### remember me
74
+ ### Remember Me
75
+
79
76
  ```ruby
80
- auto_login(user, should_remember=false) # login without credentials, optional remember_me
77
+ auto_login(user, should_remember = false) # Login without credentials, optional remember_me
81
78
  remember_me!
82
79
  forget_me!
80
+ force_forget_me! # Forgets all sessions by clearing the token, even if remember_me_token_persist_globally is set to true
83
81
  ```
84
82
 
85
- ### reset password
83
+ ### Reset Password
84
+
86
85
  ```ruby
87
86
  User.load_from_reset_password_token(token)
88
- @user.generate_reset_password_token! # if you want to send the email by youself
89
- @user.deliver_reset_password_instructions! # generates the token and sends the email
87
+ @user.generate_reset_password_token! # Use if you want to send the email by yourself
88
+ @user.deliver_reset_password_instructions! # Generates the token and sends the email
90
89
  @user.change_password!(new_password)
91
90
  ```
92
91
 
93
- ### user activation
92
+ ### User Activation
93
+
94
94
  ```ruby
95
95
  User.load_from_activation_token(token)
96
96
  @user.setup_activation
@@ -101,272 +101,124 @@ Please see the tutorials in the github wiki for detailed usage information.
101
101
 
102
102
  ## Installation
103
103
 
104
- If using bundler, first add 'sorcery' to your Gemfile:
104
+ Add this line to your application's Gemfile:
105
105
 
106
106
  ```ruby
107
- gem "sorcery"
107
+ gem 'sorcery'
108
108
  ```
109
109
 
110
- And run
110
+ And then execute:
111
111
 
112
- ```ruby
113
- bundle install
114
- ```
112
+ $ bundle
115
113
 
116
- Otherwise simply
114
+ Or install it yourself as:
117
115
 
118
- ```ruby
119
- gem install sorcery
120
- ```
116
+ $ gem install sorcery
121
117
 
122
- ## Rails configuration
118
+ ## Configuration
123
119
 
124
- ```bash
125
- rails generate sorcery:install
126
- ```
120
+ Run the following command to generate the core migration file, the initializer file and the
121
+ `User` model class.
127
122
 
128
- This will generate the core migration file, the initializer file and the
129
- 'User' model class.
123
+ $ rails generate sorcery:install
130
124
 
131
- ```bash
132
- rails generate sorcery:install remember_me reset_password
133
- ```
125
+ Run the following command generate the migrations files for remember_me and reset_password submodules and will create the initializer file (and add submodules to it), and create the `User` model class.
134
126
 
135
- This will generate the migrations files for remember_me and reset_password
136
- submodules and will create the initializer file (and add submodules to it),
137
- and create the 'User' model class.
127
+ $ rails generate sorcery:install remember_me reset_password
138
128
 
139
- ```bash
140
- rails generate sorcery:install --model Person
141
- ```
129
+ Run the following command to generate the core migration file, the initializer and change the model class (in the initializer and migration files) to the class `Person` (and its pluralized version, 'people')
142
130
 
143
- This will generate the core migration file, the initializer and change the
144
- model class (in the initializer and migration files) to the class 'Person'
145
- (and its pluralized version, 'people')
131
+ $ rails generate sorcery:install --model Person
146
132
 
147
- ```bash
148
- rails generate sorcery:install http_basic_auth external remember_me --only-submodules
149
- ```
133
+ Run the following command to generate only the migration files for the specified submodules and will add them to the initializer file.
150
134
 
151
- This will generate only the migration files for the specified submodules and
152
- will add them to the initializer file.
135
+ $ rails generate sorcery:install http_basic_auth external remember_me --only-submodules
153
136
 
154
137
  Inside the initializer, the comments will tell you what each setting does.
155
138
 
156
- ## DelayedJob Integration
157
-
158
- By default emails are sent synchronously. You can send them asynchronously by
159
- using the [delayed_job gem](https://github.com/collectiveidea/delayed_job).
160
-
161
- After implementing the `delayed_job` into your project add the code below at
162
- the end of the `config/initializers/sorcery.rb` file. After that all emails
163
- will be sent asynchronously.
164
-
165
- ```ruby
166
- module Sorcery
167
- module Model
168
- module InstanceMethods
169
- def generic_send_email(method, mailer)
170
- config = sorcery_config
171
- mail = config.send(mailer).delay.send(config.send(method), self)
172
- end
173
- end
174
- end
175
- end
176
- ```
177
-
178
- Sidekiq and Resque integrations are coming soon.
179
-
180
- ## Single Table Inheritance (STI) Support
181
- STI is supported via a single setting in config/initializers/sorcery.rb.
182
-
183
- ## Full Features List by module
184
-
185
- **Core** (see [lib/sorcery/model.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model.rb) and
186
- [lib/sorcery/controller.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller.rb)):
187
-
188
- * login/logout, optional return user to requested url on login, configurable
189
- redirect for non-logged-in users.
190
- * password encryption, algorithms: bcrypt(default), md5, sha1, sha256,
191
- sha512, aes256, custom(yours!), none. Configurable stretches and salt.
192
- * configurable attribute names for username, password and email.
193
- * allow multiple fields to serve as username.
194
-
195
-
196
- **User Activation** (see [lib/sorcery/model/submodules/user_activation.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/user_activation.rb)):
197
-
198
- * User activation by email with optional success email.
199
- * configurable attribute names.
200
- * configurable mailer, method name, and attribute name.
201
- * configurable temporary token expiration.
202
- * Optionally prevent non-active users to login.
139
+ ## Full Features List by Module
203
140
 
141
+ **Core** (see [lib/sorcery/model.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model.rb) and [lib/sorcery/controller.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller.rb)):
204
142
 
205
- **Reset Password** (see [lib/sorcery/model/submodules/reset_password.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/reset_password.rb)):
143
+ - Login / logout, optional return user to requested url on login, configurable redirect for non-logged-in users.
144
+ - Password encryption, algorithms: bcrypt (default), MD5, SHA-1, SHA-256, SHA-512, AES or custom. Configurable stretches and salt.
145
+ - Configurable attribute names for username, password and email.
146
+ - Allow multiple fields to serve as username.
206
147
 
207
- * Reset password with email verification.
208
- * configurable mailer, method name, and attribute name.
209
- * configurable temporary token expiration.
210
- * configurable time between emails (hammering protection).
148
+ **User Activation** (see [lib/sorcery/model/submodules/user_activation.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/user_activation.rb)):
211
149
 
150
+ - User activation by email with optional success email
151
+ - Configurable attribute names
152
+ - Configurable mailer, method name, and attribute name
153
+ - Configurable temporary token expiration
154
+ - Optionally prevent non-active users to login
212
155
 
213
- **Remember Me** (see [lib/sorcery/model/submodules/remember_me.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/remember_me.rb)):
156
+ **Reset Password** (see [lib/sorcery/model/submodules/reset_password.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/reset_password.rb)):
214
157
 
215
- * Remember me with configurable expiration.
216
- * configurable attribute names.
158
+ - Reset password with email verification
159
+ - Configurable mailer, method name, and attribute name
160
+ - Configurable temporary token expiration
161
+ - Configurable time between emails (hammering protection)
217
162
 
163
+ **Remember Me** (see [lib/sorcery/model/submodules/remember_me.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/remember_me.rb)):
218
164
 
219
- **Session Timeout** (see [lib/sorcery/controller/submodules/session_timeout.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/session_timeout.rb)):
165
+ - Remember me with configurable expiration
166
+ - Configurable attribute names
167
+ - Configurable to persist globally (supporting multiple browsers at the same time), or starting anew after each login
220
168
 
221
- * Configurable session timeout.
222
- * Optionally session timeout will be calculated from last user action.
169
+ **Session Timeout** (see [lib/sorcery/controller/submodules/session_timeout.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/session_timeout.rb)):
223
170
 
171
+ - Configurable session timeout
172
+ - Optionally session timeout will be calculated from last user action
224
173
 
225
- **Brute Force Protection** (see [lib/sorcery/model/submodules/brute_force_protection.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/brute_force_protection.rb)):
174
+ **Brute Force Protection** (see [lib/sorcery/model/submodules/brute_force_protection.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/brute_force_protection.rb)):
226
175
 
227
- * Brute force login hammering protection.
228
- * configurable logins before lock and lock duration.
176
+ - Brute force login hammering protection
177
+ - configurable logins before lock and lock duration
229
178
 
179
+ **Basic HTTP Authentication** (see [lib/sorcery/controller/submodules/http_basic_auth.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/http_basic_auth.rb)):
230
180
 
231
- **Basic HTTP Authentication** (see [lib/sorcery/controller/submodules/http_basic_auth.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/http_basic_auth.rb)):
181
+ - A before action for requesting authentication with HTTP Basic
182
+ - Automatic login from HTTP Basic
183
+ - Automatic login is disabled if session key changed
232
184
 
233
- * A before filter for requesting authentication with HTTP Basic.
234
- * automatic login from HTTP Basic.
235
- * automatic login is disabled if session key changed.
185
+ **Activity Logging** (see [lib/sorcery/model/submodules/activity_logging.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/model/submodules/activity_logging.rb)):
236
186
 
187
+ - Automatic logging of last login, last logout, last activity time and IP address for last login
188
+ - Configurable timeout by which to decide whether to include a user in the list of logged in users
237
189
 
238
- **Activity Logging** (see [lib/sorcery/model/submodules/activity_logging.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/model/submodules/activity_logging.rb)):
190
+ **External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/Sorcery/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
239
191
 
240
- * automatic logging of last login, last logout, last activity time and IP
241
- address for last login.
242
- * an easy method of collecting the list of currently logged in users.
243
- * configurable timeout by which to decide whether to include a user in the
244
- list of logged in users.
192
+ - OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku, LinkedIn, VK, LiveID, Xing, Salesforce)
193
+ - Configurable database column names
194
+ - Authentications table
245
195
 
196
+ ## Planned Features
246
197
 
247
- **External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
198
+ - Passing a block to encrypt, allowing the developer to define his own mix of salting and encrypting
199
+ - Forgot username, maybe as part of the reset_password module
200
+ - Scoping logins (to a subdomain or another arbitrary field)
201
+ - Allowing storing the salt and encrypted password in the same DB field for extra security
202
+ - Other reset password strategies (security questions?)
203
+ - Other brute force protection strategies (captcha)
248
204
 
249
- * OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku,
250
- LinkedIn, VK, LiveID, Xing, and Salesforce)
251
- * configurable db field names and authentications table.
205
+ Have an idea? Let us know, and it might get into the gem!
252
206
 
207
+ ## Contributing
253
208
 
254
- ## Next Planned Features
255
-
256
- I've got some thoughts which include (unordered):
257
-
258
- * Passing a block to encrypt, allowing the developer to define his own mix
259
- of salting and encrypting
260
- * Forgot username, maybe as part of the reset_password module
261
- * Scoping logins (to a subdomain or another arbitrary field)
262
- * Allowing storing the salt and crypted password in the same DB field for
263
- extra security
264
- * Other reset password strategies (security questions?)
265
- * Other brute force protection strategies (captcha)
266
-
267
-
268
- Have an idea? Let me know, and it might get into the gem!
269
-
270
- ## Backward compatibility
271
-
272
- While the lib is young and evolving fast I'm breaking backward compatibility
273
- quite often. I'm constantly finding better ways to do things and throwing away
274
- old ways. To let you know when things are changing in a non-compatible way,
275
- I'm bumping the minor version of the gem. The patch version changes are
276
- backward compatible.
277
-
278
- In short, an app that works with x.3.1 should be able to upgrade to x.3.2 with
279
- no code changes. The same cannot be said about upgrading to x.4.0 and above,
280
- however.
281
-
282
- ## DataMapper Support
283
-
284
- Important notes:
285
-
286
- * Expected to work with DM adapters: dm-mysql-adapter,
287
- dm-redis-adapter.
288
- * Submodules DM adapter dependent: activity_logging (dm-mysql-adapter)
289
- * Usage: include DataMapper::Resource in user model, follow sorcery
290
- instructions (remember to add property id, validators and accessor
291
- attributes such as password and password_confirmation)
292
- * Option downcase__username_before_authenticating and dm-mysql,
293
- http://datamapper.lighthouseapp.com/projects/20609/tickets/1105-add-support-for-definingchanging-default-collation
294
-
295
- ## Upgrading
296
-
297
- Important notes while upgrading:
298
-
299
- * If you are upgrading from <= **0.8.6** and you use Sorcery model methods in your app,
300
- you might need to change them from `user.method` to `user.sorcery_adapter.method` and from
301
- `User.method` to `User.sorcery_adapter_method`
302
-
303
- * If you are upgrading from <= **0.8.5** and you're using Sorcery test helpers,
304
- you need to change the way you include them to following code:
305
-
306
- ```ruby
307
- RSpec.configure do |config|
308
- config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
309
- config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
310
- end
311
- ```
312
-
313
- * If are upgrading to **0.8.2** and use activity_logging feature with
314
- ActiveRecord, you will have to add a new column
315
- `last_login_from_ip_address`
316
- [#465](https://github.com/NoamB/sorcery/issues/465)
317
- * Sinatra support existed until **v0.7.0** (including), but was dropped
318
- later due to being a maintenance nightmare.
319
- * If upgrading from <= **0.6.1 to >= **0.7.0** you need to change
320
- 'username
321
- _attribute_name' to 'username_attribute_names' in initializer.
322
- * If upgrading from <= **v0.5.1** to >= **v0.5.2** you need to explicitly
323
- set your user_class model in the initializer file.
324
-
325
- ```ruby
326
- # This line must come after the 'user config' block.
327
- config.user_class = User
328
- ```
329
-
330
-
331
- ## Contributing to sorcery
332
-
333
- Your feedback is very welcome and will make this gem much much better for you,
334
- me and everyone else. Besides feedback on code, features, suggestions and bug
335
- reports, you may want to actually make an impact on the code. For this:
336
-
337
- * Fork it.
338
- * Fix it.
339
- * Test it.
340
- * Commit it.
341
- * Send me a pull request so I'll... Pull it.
342
-
209
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Sorcery/sorcery.
343
210
 
344
211
  If you feel sorcery has made your life easier, and you would like to express
345
- your thanks via a donation, my paypal email is in the contact details.
212
+ your thanks via a donation, my PayPal email is in the contact details.
346
213
 
347
214
  ## Contact
348
215
 
349
216
  Feel free to ask questions using these contact details:
350
217
 
351
- #### Noam Ben-Ari
352
-
353
- email: nbenari@gmail.com ( also for paypal )
354
-
355
- twitter: @nbenari
356
-
357
- #### Kir Shatrov
358
-
359
- email: shatrov@me.com
360
-
361
- twitter: @Kiiiir
362
-
363
- #### Grzegorz Witek
364
-
365
- email: arnvald.to@gmail.com
366
-
367
- twitter: @arnvald
218
+ - Noam Ben-Ari: [nbenari@gmail.com](mailto:nbenari@gmail.com) (also PayPal), [Twitter](https://twitter.com/nbenari)
219
+ - Kir Shatrov: [shatrov@me.com](mailto:shatrov@me.com), [Twitter](https://twitter.com/Kiiiir)
220
+ - Grzegorz Witek: [arnvald.to@gmail.com](mailto:arnvald.to@gmail.com), [Twitter](https://twitter.com/arnvald)
368
221
 
369
- ## Copyright
222
+ ## License
370
223
 
371
- Copyright (c) 2010-2014 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
372
- further details.
224
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).