sorcery 0.8.6 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +75 -14
- data/CHANGELOG.md +32 -1
- data/Gemfile +1 -0
- data/README.md +138 -86
- data/gemfiles/active_record-rails40.gemfile +7 -0
- data/gemfiles/active_record-rails41.gemfile +3 -2
- data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +2 -1
- data/gemfiles/mongoid-rails40.gemfile +9 -0
- data/gemfiles/mongoid-rails41.gemfile +3 -5
- data/gemfiles/mongoid3-rails32.gemfile +9 -0
- data/lib/generators/sorcery/USAGE +1 -1
- data/lib/generators/sorcery/install_generator.rb +19 -5
- data/lib/generators/sorcery/templates/initializer.rb +36 -10
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
- data/lib/generators/sorcery/templates/migration/core.rb +2 -2
- data/lib/generators/sorcery/templates/migration/external.rb +3 -1
- data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
- data/lib/sorcery/adapters/base_adapter.rb +30 -0
- data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
- data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
- data/lib/sorcery/controller/config.rb +65 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +16 -21
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
- data/lib/sorcery/controller/submodules/external.rb +9 -29
- data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
- data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
- data/lib/sorcery/controller.rb +5 -64
- data/lib/sorcery/model/config.rb +96 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +29 -36
- data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -37
- data/lib/sorcery/model/submodules/external.rb +53 -9
- data/lib/sorcery/model/submodules/remember_me.rb +12 -31
- data/lib/sorcery/model/submodules/reset_password.rb +21 -39
- data/lib/sorcery/model/submodules/user_activation.rb +21 -63
- data/lib/sorcery/model/temporary_token.rb +4 -4
- data/lib/sorcery/model.rb +47 -175
- data/lib/sorcery/providers/base.rb +11 -0
- data/lib/sorcery/providers/facebook.rb +16 -5
- data/lib/sorcery/providers/github.rb +11 -2
- data/lib/sorcery/providers/google.rb +1 -1
- data/lib/sorcery/providers/heroku.rb +57 -0
- data/lib/sorcery/providers/jira.rb +77 -0
- data/lib/sorcery/providers/linkedin.rb +1 -1
- data/lib/sorcery/providers/liveid.rb +1 -1
- data/lib/sorcery/providers/salesforce.rb +50 -0
- data/lib/sorcery/providers/twitter.rb +1 -1
- data/lib/sorcery/providers/vk.rb +6 -4
- data/lib/sorcery/providers/xing.rb +2 -2
- data/lib/sorcery/test_helpers/internal.rb +7 -3
- data/lib/sorcery/test_helpers/rails/controller.rb +5 -1
- data/lib/sorcery/version.rb +3 -0
- data/lib/sorcery.rb +75 -43
- data/sorcery.gemspec +6 -2
- data/spec/active_record/user_activity_logging_spec.rb +9 -0
- data/spec/controllers/controller_activity_logging_spec.rb +124 -0
- data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
- data/spec/{active_record → controllers}/controller_http_basic_auth_spec.rb +14 -11
- data/spec/{active_record → controllers}/controller_oauth2_spec.rb +151 -64
- data/spec/{active_record → controllers}/controller_oauth_spec.rb +94 -70
- data/spec/{active_record → controllers}/controller_remember_me_spec.rb +32 -12
- data/spec/{active_record → controllers}/controller_session_timeout_spec.rb +15 -5
- data/spec/{shared_examples/controller_shared_examples.rb → controllers/controller_spec.rb} +34 -19
- data/spec/{datamapper → data_mapper}/user_activation_spec.rb +1 -1
- data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
- data/spec/{datamapper → data_mapper}/user_brute_force_protection_spec.rb +1 -1
- data/spec/{datamapper → data_mapper}/user_oauth_spec.rb +1 -1
- data/spec/{datamapper → data_mapper}/user_remember_me_spec.rb +1 -1
- data/spec/{datamapper → data_mapper}/user_reset_password_spec.rb +1 -1
- data/spec/{datamapper → data_mapper}/user_spec.rb +1 -1
- data/spec/mongoid/user_spec.rb +13 -0
- data/spec/orm/active_record.rb +12 -0
- data/spec/orm/{datamapper.rb → data_mapper.rb} +16 -2
- data/spec/orm/mongo_mapper.rb +0 -1
- data/spec/orm/mongoid.rb +4 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +62 -1
- data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
- data/spec/rails_app/config/routes.rb +9 -0
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
- data/spec/shared_examples/user_activation_shared_examples.rb +7 -7
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +73 -5
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +127 -9
- data/spec/shared_examples/user_oauth_shared_examples.rb +3 -6
- data/spec/shared_examples/user_remember_me_shared_examples.rb +6 -3
- data/spec/shared_examples/user_reset_password_shared_examples.rb +10 -10
- data/spec/shared_examples/user_shared_examples.rb +146 -46
- data/spec/spec_helper.rb +7 -22
- metadata +36 -57
- data/Gemfile.rails4 +0 -22
- data/VERSION +0 -1
- data/lib/sorcery/model/adapters/active_record.rb +0 -54
- data/lib/sorcery/model/adapters/datamapper.rb +0 -123
- data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -60
- data/lib/sorcery/model/adapters/mongoid.rb +0 -88
- data/lib/sorcery/test_helpers/rails.rb +0 -7
- data/spec/active_record/controller_activity_logging_spec.rb +0 -29
- data/spec/active_record/controller_brute_force_protection_spec.rb +0 -158
- data/spec/active_record/controller_spec.rb +0 -8
- data/spec/active_record/integration_spec.rb +0 -23
- data/spec/datamapper/controller_activity_logging_spec.rb +0 -17
- data/spec/datamapper/controller_spec.rb +0 -8
- data/spec/datamapper/user_activity_logging_spec.rb +0 -9
- data/spec/mongo_mapper/controller_spec.rb +0 -8
- data/spec/mongoid/controller_activity_logging_spec.rb +0 -16
- data/spec/mongoid/controller_spec.rb +0 -8
- data/spec/rails_app/public/404.html +0 -26
- data/spec/rails_app/public/422.html +0 -26
- data/spec/rails_app/public/500.html +0 -26
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/images/rails.png +0 -0
- data/spec/rails_app/public/javascripts/application.js +0 -2
- data/spec/rails_app/public/javascripts/controls.js +0 -965
- data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
- data/spec/rails_app/public/javascripts/effects.js +0 -1123
- data/spec/rails_app/public/javascripts/prototype.js +0 -6001
- data/spec/rails_app/public/javascripts/rails.js +0 -175
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
- data/spec/shared_examples/controller_activity_logging_shared_examples.rb +0 -125
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -52
- data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -62
- /data/spec/rails_app/app/{datamapper → data_mapper}/authentication.rb +0 -0
- /data/spec/rails_app/app/{datamapper → data_mapper}/user.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5c0e37f33ed4fa3e085ccc8e3a6a5526afb632f2
|
|
4
|
+
data.tar.gz: 1b224ad20e8ed01e04a2b7a25153e5949b56fa4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 48d1dd07a9ab99ade78c490bfffd27144b3951d5ba1f45bcfc1baede6db4cbe228e8916025bfd69fbc48d3342724b00ac2cfd9ecc41110d1b9fdd9559885091b
|
|
7
|
+
data.tar.gz: 250ceb737b38dab40dd3e16488f3e37aadf2b09fe94c6147ed92a2d42aab2d61d01601b3a2891403f70cc23ef4e675f4fb1ad83072d59ee71d8d6e5fd9d9c20d
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
|
@@ -8,30 +8,19 @@ services: mongodb
|
|
|
8
8
|
|
|
9
9
|
gemfile:
|
|
10
10
|
- Gemfile
|
|
11
|
-
- Gemfile.rails4
|
|
12
11
|
|
|
13
12
|
env:
|
|
14
13
|
- "SORCERY_ORM=active_record"
|
|
15
14
|
- "SORCERY_ORM=mongoid"
|
|
16
15
|
- "SORCERY_ORM=mongo_mapper"
|
|
17
|
-
- "SORCERY_ORM=
|
|
16
|
+
- "SORCERY_ORM=data_mapper"
|
|
18
17
|
|
|
19
18
|
before_script:
|
|
20
19
|
- mysql -e 'create database sorcery_test;'
|
|
21
20
|
|
|
22
21
|
matrix:
|
|
23
|
-
|
|
24
|
-
- rvm:
|
|
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"
|
|
22
|
+
allow_failures:
|
|
23
|
+
- rvm: :jruby
|
|
35
24
|
|
|
36
25
|
include:
|
|
37
26
|
- rvm: 1.9.3
|
|
@@ -46,6 +35,10 @@ matrix:
|
|
|
46
35
|
gemfile: gemfiles/mongoid-rails41.gemfile
|
|
47
36
|
env: "SORCERY_ORM=mongoid"
|
|
48
37
|
|
|
38
|
+
- rvm: jruby
|
|
39
|
+
gemfile: gemfiles/mongoid-rails41.gemfile
|
|
40
|
+
env: "SORCERY_ORM=mongoid"
|
|
41
|
+
|
|
49
42
|
- rvm: 1.9.3
|
|
50
43
|
gemfile: gemfiles/mongo_mapper-rails41.gemfile
|
|
51
44
|
env: "SORCERY_ORM=mongo_mapper"
|
|
@@ -58,6 +51,10 @@ matrix:
|
|
|
58
51
|
gemfile: gemfiles/mongo_mapper-rails41.gemfile
|
|
59
52
|
env: "SORCERY_ORM=mongo_mapper"
|
|
60
53
|
|
|
54
|
+
- rvm: jruby
|
|
55
|
+
gemfile: gemfiles/mongo_mapper-rails41.gemfile
|
|
56
|
+
env: "SORCERY_ORM=mongo_mapper"
|
|
57
|
+
|
|
61
58
|
- rvm: 1.9.3
|
|
62
59
|
gemfile: gemfiles/active_record-rails41.gemfile
|
|
63
60
|
env: "SORCERY_ORM=active_record"
|
|
@@ -69,3 +66,67 @@ matrix:
|
|
|
69
66
|
- rvm: 2.1
|
|
70
67
|
gemfile: gemfiles/active_record-rails41.gemfile
|
|
71
68
|
env: "SORCERY_ORM=active_record"
|
|
69
|
+
|
|
70
|
+
- rvm: jruby
|
|
71
|
+
gemfile: gemfiles/active_record-rails41.gemfile
|
|
72
|
+
env: "SORCERY_ORM=active_record"
|
|
73
|
+
|
|
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
|
|
107
|
+
gemfile: gemfiles/active_record-rails40.gemfile
|
|
108
|
+
env: "SORCERY_ORM=active_record"
|
|
109
|
+
|
|
110
|
+
- rvm: 2.0.0
|
|
111
|
+
gemfile: gemfiles/active_record-rails40.gemfile
|
|
112
|
+
env: "SORCERY_ORM=active_record"
|
|
113
|
+
|
|
114
|
+
- rvm: 2.1
|
|
115
|
+
gemfile: gemfiles/active_record-rails40.gemfile
|
|
116
|
+
env: "SORCERY_ORM=active_record"
|
|
117
|
+
|
|
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"
|
|
125
|
+
|
|
126
|
+
- rvm: 2.0.0
|
|
127
|
+
gemfile: gemfiles/mongoid3-rails32.gemfile
|
|
128
|
+
env: "SORCERY_ORM=mongoid"
|
|
129
|
+
|
|
130
|
+
- rvm: 2.1
|
|
131
|
+
gemfile: gemfiles/mongoid3-rails32.gemfile
|
|
132
|
+
env: "SORCERY_ORM=mongoid"
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## 0
|
|
3
|
+
## 1.0 (not released yet)
|
|
4
|
+
|
|
5
|
+
* Adapters (Mongoid, MongoMapper, DataMapper) are now separated from the core Sorcery repo and moved under `sorcery-rails` organization. Special thanks to @juike!
|
|
6
|
+
|
|
7
|
+
## 0.9.1
|
|
8
|
+
|
|
9
|
+
* Fixed fetching private emails from github (thanks to @saratovsource)
|
|
10
|
+
* Added support for `active_for_authentication?` method (thanks to @gchaincl)
|
|
11
|
+
* Fixed migration bug for `external` submodule (thanks to @skv-headless)
|
|
12
|
+
* Added support for new Facebook Graph API (thanks to @mchaisse)
|
|
13
|
+
* Fixed issue with Xing submodule (thanks to @yoyostile)
|
|
14
|
+
* Fixed security bug with using `state` field in oAuth requests
|
|
15
|
+
|
|
16
|
+
## 0.9.0
|
|
17
|
+
|
|
18
|
+
* Sending emails works with Rails 4.2 (thanks to @wooly)
|
|
19
|
+
* Added `valid_password?` method
|
|
20
|
+
* Added support for JIRA OAuth (thanks to @camilasan)
|
|
21
|
+
* Added support for Heroku OAuth (thanks to @tyrauber)
|
|
22
|
+
* Added support for Salesforce OAuth (thanks to @supremebeing7)
|
|
23
|
+
* Added support for Mongoid 4
|
|
24
|
+
* Fixed issues with empty passwords (thanks to @Borzik)
|
|
25
|
+
* `find_by_provider_and_uid` method was replaced with `find_by_oauth_credentials`
|
|
26
|
+
* Sorcery::VERSION constant was added to allow easy version check
|
|
27
|
+
* `@user.setup_activation` method was made to be public (thanks @iTakeshi)
|
|
28
|
+
* `current_users` method is deprecated
|
|
29
|
+
* Fetching email from VK auth, thanks to @makaroni4
|
|
30
|
+
* Add logged_in? method to test_helpers (thanks to @oriolbcn)
|
|
31
|
+
* #locked? method is now public API (thanks @rogercampos)
|
|
32
|
+
* Introduces a new User instance method `generate_reset_password_token` to generate a new reset password token without sending an email (thanks to @tbuehl)
|
|
33
|
+
|
|
34
|
+
## 0.8.6
|
|
4
35
|
|
|
5
36
|
* `current_user` returns `nil` instead of `false` if there's no user loggd in (#493)
|
|
6
37
|
* 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)
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
[](https://travis-ci.org/NoamB/sorcery)
|
|
2
2
|
[](https://codeclimate.com/github/NoamB/sorcery)
|
|
3
|
+
[](http://inch-ci.org/github/NoamB/sorcery)
|
|
3
4
|
|
|
4
5
|
# sorcery
|
|
5
6
|
Magical Authentication for Rails 3 and 4. Supports ActiveRecord,
|
|
@@ -9,9 +10,11 @@ Inspired by restful_authentication, Authlogic and Devise. Crypto code taken
|
|
|
9
10
|
almost unchanged from Authlogic. OAuth code inspired by OmniAuth and Ryan
|
|
10
11
|
Bates's railscasts about it.
|
|
11
12
|
|
|
12
|
-
**
|
|
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.
|
|
13
15
|
|
|
14
|
-
**Rails 4
|
|
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.
|
|
15
18
|
|
|
16
19
|
https://github.com/NoamB/sorcery/wiki/Simple-Password-Authentication
|
|
17
20
|
|
|
@@ -33,94 +36,117 @@ can write your own authentication flow. It was built with a few goals in mind:
|
|
|
33
36
|
|
|
34
37
|
Hopefully, I've achieved this. If not, let me know.
|
|
35
38
|
|
|
36
|
-
## Useful Links
|
|
39
|
+
## Useful Links
|
|
37
40
|
|
|
38
|
-
|
|
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)
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
https://github.com/NoamB/sorcery-example-app
|
|
42
|
-
|
|
43
|
-
Documentation: http://rubydoc.info/gems/sorcery
|
|
44
|
-
|
|
45
|
-
Check out the tutorials in the github wiki!
|
|
44
|
+
Check out the tutorials in the [Wiki](https://github.com/NoamB/sorcery/wiki) for more!
|
|
46
45
|
|
|
47
46
|
## API Summary
|
|
48
47
|
|
|
49
48
|
Below is a summary of the library methods. Most method names are self
|
|
50
49
|
explaining and the rest are commented:
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
51
|
+
|
|
52
|
+
### core
|
|
53
|
+
```ruby
|
|
54
|
+
require_login # this is a before filter
|
|
55
|
+
login(email, password, remember_me = false)
|
|
56
|
+
auto_login(user)# login without credentials
|
|
57
|
+
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
|
|
63
|
+
User.authenticates_with_sorcery!
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### http basic auth
|
|
67
|
+
```ruby
|
|
68
|
+
require_login_from_http_basic # this is a before filter
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### external
|
|
72
|
+
```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.
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### remember me
|
|
79
|
+
```ruby
|
|
80
|
+
auto_login(user, should_remember=false) # login without credentials, optional remember_me
|
|
81
|
+
remember_me!
|
|
82
|
+
forget_me!
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### reset password
|
|
86
|
+
```ruby
|
|
87
|
+
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
|
|
90
|
+
@user.change_password!(new_password)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### user activation
|
|
94
|
+
```ruby
|
|
95
|
+
User.load_from_activation_token(token)
|
|
96
|
+
@user.setup_activation
|
|
97
|
+
@user.activate!
|
|
98
|
+
```
|
|
87
99
|
|
|
88
100
|
Please see the tutorials in the github wiki for detailed usage information.
|
|
89
101
|
|
|
90
|
-
## Installation
|
|
102
|
+
## Installation
|
|
91
103
|
|
|
92
104
|
If using bundler, first add 'sorcery' to your Gemfile:
|
|
93
105
|
|
|
94
|
-
|
|
106
|
+
```ruby
|
|
107
|
+
gem "sorcery"
|
|
108
|
+
```
|
|
95
109
|
|
|
96
110
|
And run
|
|
97
111
|
|
|
98
|
-
|
|
112
|
+
```ruby
|
|
113
|
+
bundle install
|
|
114
|
+
```
|
|
99
115
|
|
|
100
116
|
Otherwise simply
|
|
101
117
|
|
|
102
|
-
|
|
118
|
+
```ruby
|
|
119
|
+
gem install sorcery
|
|
120
|
+
```
|
|
103
121
|
|
|
104
|
-
## Rails configuration
|
|
122
|
+
## Rails configuration
|
|
105
123
|
|
|
106
|
-
|
|
124
|
+
```bash
|
|
125
|
+
rails generate sorcery:install
|
|
126
|
+
```
|
|
107
127
|
|
|
108
128
|
This will generate the core migration file, the initializer file and the
|
|
109
129
|
'User' model class.
|
|
110
130
|
|
|
111
|
-
|
|
131
|
+
```bash
|
|
132
|
+
rails generate sorcery:install remember_me reset_password
|
|
133
|
+
```
|
|
112
134
|
|
|
113
135
|
This will generate the migrations files for remember_me and reset_password
|
|
114
136
|
submodules and will create the initializer file (and add submodules to it),
|
|
115
137
|
and create the 'User' model class.
|
|
116
138
|
|
|
117
|
-
|
|
139
|
+
```bash
|
|
140
|
+
rails generate sorcery:install --model Person
|
|
141
|
+
```
|
|
118
142
|
|
|
119
143
|
This will generate the core migration file, the initializer and change the
|
|
120
144
|
model class (in the initializer and migration files) to the class 'Person'
|
|
121
145
|
(and its pluralized version, 'people')
|
|
122
146
|
|
|
123
|
-
|
|
147
|
+
```bash
|
|
148
|
+
rails generate sorcery:install http_basic_auth external remember_me --only-submodules
|
|
149
|
+
```
|
|
124
150
|
|
|
125
151
|
This will generate only the migration files for the specified submodules and
|
|
126
152
|
will add them to the initializer file.
|
|
@@ -136,25 +162,29 @@ After implementing the `delayed_job` into your project add the code below at
|
|
|
136
162
|
the end of the `config/initializers/sorcery.rb` file. After that all emails
|
|
137
163
|
will be sent asynchronously.
|
|
138
164
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
end
|
|
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)
|
|
147
172
|
end
|
|
148
173
|
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
```
|
|
149
177
|
|
|
150
178
|
Sidekiq and Resque integrations are coming soon.
|
|
151
179
|
|
|
152
180
|
## Single Table Inheritance (STI) Support
|
|
153
181
|
STI is supported via a single setting in config/initializers/sorcery.rb.
|
|
154
182
|
|
|
155
|
-
## Full Features List by module
|
|
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)):
|
|
156
187
|
|
|
157
|
-
Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
|
|
158
188
|
* login/logout, optional return user to requested url on login, configurable
|
|
159
189
|
redirect for non-logged-in users.
|
|
160
190
|
* password encryption, algorithms: bcrypt(default), md5, sha1, sha256,
|
|
@@ -163,7 +193,8 @@ Core (see lib/sorcery/model.rb and lib/sorcery/controller.rb):
|
|
|
163
193
|
* allow multiple fields to serve as username.
|
|
164
194
|
|
|
165
195
|
|
|
166
|
-
User Activation (see lib/sorcery/model/submodules/user_activation.rb):
|
|
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
|
+
|
|
167
198
|
* User activation by email with optional success email.
|
|
168
199
|
* configurable attribute names.
|
|
169
200
|
* configurable mailer, method name, and attribute name.
|
|
@@ -171,37 +202,41 @@ User Activation (see lib/sorcery/model/submodules/user_activation.rb):
|
|
|
171
202
|
* Optionally prevent non-active users to login.
|
|
172
203
|
|
|
173
204
|
|
|
174
|
-
Reset Password (see lib/sorcery/model/submodules/reset_password.rb):
|
|
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)):
|
|
206
|
+
|
|
175
207
|
* Reset password with email verification.
|
|
176
208
|
* configurable mailer, method name, and attribute name.
|
|
177
209
|
* configurable temporary token expiration.
|
|
178
210
|
* configurable time between emails (hammering protection).
|
|
179
211
|
|
|
180
212
|
|
|
181
|
-
Remember Me (see lib/sorcery/model/submodules/remember_me.rb):
|
|
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)):
|
|
214
|
+
|
|
182
215
|
* Remember me with configurable expiration.
|
|
183
216
|
* configurable attribute names.
|
|
184
217
|
|
|
185
218
|
|
|
186
|
-
Session Timeout (see lib/sorcery/controller/submodules/session_timeout.rb):
|
|
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)):
|
|
220
|
+
|
|
187
221
|
* Configurable session timeout.
|
|
188
222
|
* Optionally session timeout will be calculated from last user action.
|
|
189
223
|
|
|
190
224
|
|
|
191
|
-
Brute Force Protection (see
|
|
192
|
-
|
|
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)):
|
|
226
|
+
|
|
193
227
|
* Brute force login hammering protection.
|
|
194
228
|
* configurable logins before lock and lock duration.
|
|
195
229
|
|
|
196
230
|
|
|
197
|
-
Basic HTTP Authentication (see
|
|
198
|
-
|
|
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)):
|
|
232
|
+
|
|
199
233
|
* A before filter for requesting authentication with HTTP Basic.
|
|
200
234
|
* automatic login from HTTP Basic.
|
|
201
235
|
* automatic login is disabled if session key changed.
|
|
202
236
|
|
|
203
237
|
|
|
204
|
-
Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
|
|
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)):
|
|
239
|
+
|
|
205
240
|
* automatic logging of last login, last logout, last activity time and IP
|
|
206
241
|
address for last login.
|
|
207
242
|
* an easy method of collecting the list of currently logged in users.
|
|
@@ -209,15 +244,17 @@ Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
|
|
|
209
244
|
list of logged in users.
|
|
210
245
|
|
|
211
246
|
|
|
212
|
-
External (see lib/sorcery/controller/submodules/external.rb):
|
|
213
|
-
|
|
214
|
-
|
|
247
|
+
**External** (see [lib/sorcery/controller/submodules/external.rb](https://github.com/NoamB/sorcery/blob/master/lib/sorcery/controller/submodules/external.rb)):
|
|
248
|
+
|
|
249
|
+
* OAuth1 and OAuth2 support (currently: Twitter, Facebook, Github, Google, Heroku,
|
|
250
|
+
LinkedIn, VK, LiveID, Xing, and Salesforce)
|
|
215
251
|
* configurable db field names and authentications table.
|
|
216
252
|
|
|
217
253
|
|
|
218
|
-
## Next Planned Features
|
|
254
|
+
## Next Planned Features
|
|
219
255
|
|
|
220
256
|
I've got some thoughts which include (unordered):
|
|
257
|
+
|
|
221
258
|
* Passing a block to encrypt, allowing the developer to define his own mix
|
|
222
259
|
of salting and encrypting
|
|
223
260
|
* Forgot username, maybe as part of the reset_password module
|
|
@@ -252,20 +289,26 @@ Important notes:
|
|
|
252
289
|
* Usage: include DataMapper::Resource in user model, follow sorcery
|
|
253
290
|
instructions (remember to add property id, validators and accessor
|
|
254
291
|
attributes such as password and password_confirmation)
|
|
255
|
-
* Option downcase__username_before_authenticating and dm-mysql,
|
|
292
|
+
* Option downcase__username_before_authenticating and dm-mysql,
|
|
256
293
|
http://datamapper.lighthouseapp.com/projects/20609/tickets/1105-add-support-for-definingchanging-default-collation
|
|
257
294
|
|
|
258
295
|
## Upgrading
|
|
259
296
|
|
|
260
297
|
Important notes while upgrading:
|
|
261
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
|
+
|
|
262
303
|
* If you are upgrading from <= **0.8.5** and you're using Sorcery test helpers,
|
|
263
304
|
you need to change the way you include them to following code:
|
|
264
305
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
+
```
|
|
269
312
|
|
|
270
313
|
* If are upgrading to **0.8.2** and use activity_logging feature with
|
|
271
314
|
ActiveRecord, you will have to add a new column
|
|
@@ -274,12 +317,15 @@ Important notes while upgrading:
|
|
|
274
317
|
* Sinatra support existed until **v0.7.0** (including), but was dropped
|
|
275
318
|
later due to being a maintenance nightmare.
|
|
276
319
|
* If upgrading from <= **0.6.1 to >= **0.7.0** you need to change
|
|
277
|
-
'
|
|
320
|
+
'username
|
|
321
|
+
_attribute_name' to 'username_attribute_names' in initializer.
|
|
278
322
|
* If upgrading from <= **v0.5.1** to >= **v0.5.2** you need to explicitly
|
|
279
323
|
set your user_class model in the initializer file.
|
|
280
324
|
|
|
281
|
-
|
|
282
|
-
|
|
325
|
+
```ruby
|
|
326
|
+
# This line must come after the 'user config' block.
|
|
327
|
+
config.user_class = User
|
|
328
|
+
```
|
|
283
329
|
|
|
284
330
|
|
|
285
331
|
## Contributing to sorcery
|
|
@@ -314,7 +360,13 @@ email: shatrov@me.com
|
|
|
314
360
|
|
|
315
361
|
twitter: @Kiiiir
|
|
316
362
|
|
|
363
|
+
#### Grzegorz Witek
|
|
364
|
+
|
|
365
|
+
email: arnvald.to@gmail.com
|
|
366
|
+
|
|
367
|
+
twitter: @arnvald
|
|
368
|
+
|
|
317
369
|
## Copyright
|
|
318
370
|
|
|
319
|
-
Copyright (c) 2010 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
|
|
371
|
+
Copyright (c) 2010-2014 Noam Ben Ari (nbenari@gmail.com). See LICENSE.txt for
|
|
320
372
|
further details.
|
|
@@ -2,10 +2,8 @@ source 'https://rubygems.org'
|
|
|
2
2
|
|
|
3
3
|
gem 'rails', '~> 4.1.0'
|
|
4
4
|
|
|
5
|
-
gem '
|
|
6
|
-
|
|
7
|
-
gem '
|
|
8
|
-
gem 'bson_ext'
|
|
9
|
-
gem 'sqlite3'
|
|
5
|
+
gem 'mongoid', '~> 4.0.0'
|
|
6
|
+
gem 'sqlite3', platform: :mri
|
|
7
|
+
gem 'activerecord-jdbcsqlite3-adapter', platform: :jruby
|
|
10
8
|
|
|
11
9
|
gemspec path: '..'
|
|
@@ -16,7 +16,7 @@ Examples:
|
|
|
16
16
|
This will generate the core migration file, the initializer and change the model class
|
|
17
17
|
(in the initializer and migration files) to the class 'Person' (and it's pluralized version, 'people')
|
|
18
18
|
|
|
19
|
-
rails generate sorcery:install http_basic_auth external remember_me --
|
|
19
|
+
rails generate sorcery:install http_basic_auth external remember_me --only-submodules
|
|
20
20
|
|
|
21
21
|
This will generate only the migration files for the specified submodules and will
|
|
22
22
|
add them to the initializer file.
|