authlogic 3.8.0 → 4.0.0
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 +7 -0
- data/.github/triage.md +87 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +62 -6
- data/.rubocop_todo.yml +51 -267
- data/.travis.yml +4 -26
- data/CHANGELOG.md +226 -2
- data/CONTRIBUTING.md +15 -5
- data/Gemfile +2 -2
- data/README.md +183 -91
- data/Rakefile +1 -1
- data/UPGRADING.md +20 -0
- data/authlogic.gemspec +25 -16
- data/lib/authlogic.rb +45 -45
- data/lib/authlogic/acts_as_authentic/base.rb +18 -11
- data/lib/authlogic/acts_as_authentic/email.rb +32 -28
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +1 -1
- data/lib/authlogic/acts_as_authentic/login.rb +32 -42
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +6 -6
- data/lib/authlogic/acts_as_authentic/password.rb +53 -31
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +18 -17
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +7 -12
- data/lib/authlogic/acts_as_authentic/queries/find_with_case.rb +64 -0
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +11 -3
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +30 -10
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +4 -4
- data/lib/authlogic/authenticates_many/association.rb +3 -3
- data/lib/authlogic/authenticates_many/base.rb +2 -2
- data/lib/authlogic/config.rb +0 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +11 -4
- data/lib/authlogic/controller_adapters/rack_adapter.rb +7 -3
- data/lib/authlogic/controller_adapters/rails_adapter.rb +2 -0
- data/lib/authlogic/crypto_providers/aes256.rb +1 -1
- data/lib/authlogic/crypto_providers/bcrypt.rb +1 -1
- data/lib/authlogic/crypto_providers/scrypt.rb +6 -6
- data/lib/authlogic/crypto_providers/sha1.rb +10 -5
- data/lib/authlogic/crypto_providers/sha256.rb +11 -8
- data/lib/authlogic/crypto_providers/wordpress.rb +2 -2
- data/lib/authlogic/i18n.rb +4 -2
- data/lib/authlogic/random.rb +10 -28
- data/lib/authlogic/regex.rb +11 -8
- data/lib/authlogic/session/activation.rb +6 -3
- data/lib/authlogic/session/active_record_trickery.rb +13 -9
- data/lib/authlogic/session/base.rb +15 -4
- data/lib/authlogic/session/brute_force_protection.rb +14 -7
- data/lib/authlogic/session/callbacks.rb +53 -30
- data/lib/authlogic/session/cookies.rb +57 -16
- data/lib/authlogic/session/existence.rb +21 -11
- data/lib/authlogic/session/foundation.rb +56 -10
- data/lib/authlogic/session/http_auth.rb +15 -8
- data/lib/authlogic/session/klass.rb +7 -5
- data/lib/authlogic/session/magic_columns.rb +24 -11
- data/lib/authlogic/session/magic_states.rb +11 -4
- data/lib/authlogic/session/params.rb +6 -2
- data/lib/authlogic/session/password.rb +46 -73
- data/lib/authlogic/session/persistence.rb +11 -7
- data/lib/authlogic/session/priority_record.rb +7 -4
- data/lib/authlogic/session/scopes.rb +15 -6
- data/lib/authlogic/session/session.rb +20 -10
- data/lib/authlogic/session/timeout.rb +2 -2
- data/lib/authlogic/session/unauthorized_record.rb +1 -1
- data/lib/authlogic/session/validation.rb +1 -1
- data/lib/authlogic/test_case.rb +65 -2
- data/lib/authlogic/test_case/mock_controller.rb +5 -4
- data/lib/authlogic/test_case/mock_cookie_jar.rb +11 -2
- data/lib/authlogic/test_case/mock_request.rb +5 -1
- data/lib/authlogic/test_case/rails_request_adapter.rb +3 -2
- data/lib/authlogic/version.rb +16 -0
- data/test/acts_as_authentic_test/email_test.rb +33 -34
- data/test/acts_as_authentic_test/logged_in_status_test.rb +1 -1
- data/test/acts_as_authentic_test/login_test.rb +73 -78
- data/test/acts_as_authentic_test/password_test.rb +30 -18
- data/test/acts_as_authentic_test/perishable_token_test.rb +9 -3
- data/test/acts_as_authentic_test/persistence_token_test.rb +4 -0
- data/test/acts_as_authentic_test/session_maintenance_test.rb +66 -14
- data/test/adapter_test.rb +21 -0
- data/test/gemfiles/Gemfile.rails-4.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +2 -2
- data/test/gemfiles/Gemfile.rails-master +6 -0
- data/test/i18n_test.rb +1 -1
- data/test/libs/company.rb +2 -2
- data/test/random_test.rb +7 -37
- data/test/session_test/active_record_trickery_test.rb +4 -3
- data/test/session_test/brute_force_protection_test.rb +8 -8
- data/test/session_test/callbacks_test.rb +1 -1
- data/test/session_test/cookies_test.rb +27 -4
- data/test/session_test/existence_test.rb +15 -4
- data/test/session_test/foundation_test.rb +16 -0
- data/test/session_test/http_auth_test.rb +3 -1
- data/test/session_test/magic_columns_test.rb +10 -12
- data/test/session_test/params_test.rb +4 -1
- data/test/session_test/password_test.rb +7 -7
- data/test/session_test/persistence_test.rb +1 -0
- data/test/session_test/scopes_test.rb +7 -7
- data/test/session_test/session_test.rb +2 -2
- data/test/session_test/timeout_test.rb +1 -1
- data/test/session_test/unauthorized_record_test.rb +1 -1
- data/test/test_helper.rb +111 -103
- metadata +68 -64
- data/test/gemfiles/Gemfile.rails-3.2.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.0.x +0 -7
- data/test/gemfiles/Gemfile.rails-4.1.x +0 -7
data/.travis.yml
CHANGED
@@ -7,42 +7,20 @@ language: ruby
|
|
7
7
|
# TODO: There's probably a way to configure the bundle path
|
8
8
|
|
9
9
|
before_install:
|
10
|
+
- gem update --system
|
10
11
|
- gem update bundler
|
11
12
|
|
12
13
|
rvm:
|
13
|
-
-
|
14
|
-
- 2.
|
15
|
-
- 2.2.6
|
16
|
-
- 2.3.3
|
14
|
+
- 2.2.9
|
15
|
+
- 2.5.0
|
17
16
|
|
18
17
|
gemfile:
|
19
|
-
- test/gemfiles/Gemfile.rails-3.2.x
|
20
|
-
- test/gemfiles/Gemfile.rails-4.0.x
|
21
|
-
- test/gemfiles/Gemfile.rails-4.1.x
|
22
18
|
- test/gemfiles/Gemfile.rails-4.2.x
|
23
19
|
- test/gemfiles/Gemfile.rails-5.0.x
|
24
20
|
- test/gemfiles/Gemfile.rails-5.1.x
|
21
|
+
- test/gemfiles/Gemfile.rails-5.2.x
|
25
22
|
|
26
23
|
matrix:
|
27
|
-
exclude:
|
28
|
-
- rvm: 1.9.3
|
29
|
-
gemfile: test/gemfiles/Gemfile.rails-4.1.x
|
30
|
-
- rvm: 1.9.3
|
31
|
-
gemfile: test/gemfiles/Gemfile.rails-5.0.x
|
32
|
-
- rvm: 1.9.3
|
33
|
-
gemfile: test/gemfiles/Gemfile.rails-5.1.x
|
34
|
-
- rvm: 1.9.3
|
35
|
-
gemfile: test/gemfiles/Gemfile.rails-5.2.x
|
36
|
-
- rvm: 2.1.10
|
37
|
-
gemfile: test/gemfiles/Gemfile.rails-5.0.x
|
38
|
-
- rvm: 2.1.10
|
39
|
-
gemfile: test/gemfiles/Gemfile.rails-5.1.x
|
40
|
-
- rvm: 2.1.10
|
41
|
-
gemfile: test/gemfiles/Gemfile.rails-5.2.x
|
42
|
-
- rvm: 2.2.6
|
43
|
-
gemfile: test/gemfiles/Gemfile.rails-3.2.x
|
44
|
-
- rvm: 2.3.3
|
45
|
-
gemfile: test/gemfiles/Gemfile.rails-3.2.x
|
46
24
|
fast_finish: true
|
47
25
|
|
48
26
|
sudo: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,229 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
3
|
+
## Unreleased
|
4
4
|
|
5
|
-
|
5
|
+
* Breaking Changes
|
6
|
+
* None
|
7
|
+
* Added
|
8
|
+
* None
|
9
|
+
* Fixed
|
10
|
+
* None
|
11
|
+
|
12
|
+
## 4.0.0 (2018-03-18)
|
13
|
+
|
14
|
+
* Breaking Changes, Major
|
15
|
+
* Drop support for ruby < 2.2
|
16
|
+
* Drop support for rails < 4.2
|
17
|
+
* HTTP Basic Auth is now disabled by default (use allow_http_basic_auth to enable)
|
18
|
+
* 'httponly' and 'secure' cookie options are enabled by default now
|
19
|
+
* maintain_sessions config has been removed. It has been split into 2 new options:
|
20
|
+
log_in_after_create & log_in_after_password_change (@lucasminissale)
|
21
|
+
* [#558](https://github.com/binarylogic/authlogic/pull/558) Passing an
|
22
|
+
ActionController::Parameters into authlogic will now raise an error
|
23
|
+
|
24
|
+
* Breaking Changes, Minor
|
25
|
+
* Methods in Authlogic::Random are now module methods, and are no longer
|
26
|
+
instance methods. Previously, there were both. Do not use Authlogic::Random
|
27
|
+
as a mixin.
|
28
|
+
* Our mutable constants (e.g. arrays, hashes) are now frozen.
|
29
|
+
|
30
|
+
* Added
|
31
|
+
* `Authlogic.gem_version`
|
32
|
+
* [#586](https://github.com/binarylogic/authlogic/pull/586) Support for SameSite cookies
|
33
|
+
* [#581](https://github.com/binarylogic/authlogic/pull/581) Support for rails 5.2
|
34
|
+
* Support for ruby 2.4, specifically openssl gem 2.0
|
35
|
+
* [#98](https://github.com/binarylogic/authlogic/issues/98)
|
36
|
+
I18n for invalid session error message. (@eugenebolshakov)
|
37
|
+
|
38
|
+
* Fixed
|
39
|
+
* Random.friendly_token (used for e.g. perishable token) now returns strings
|
40
|
+
of consistent length, and conforms better to RFC-4648
|
41
|
+
* ensure that login field validation uses correct locale (@sskirby)
|
42
|
+
* add a respond_to_missing? in AbstractAdapter that also checks controller respond_to?
|
43
|
+
* [#561](https://github.com/binarylogic/authlogic/issues/561) authenticates_many now works with scope_cookies:true
|
44
|
+
* Allow tld up to 24 characters per https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
45
|
+
|
46
|
+
## 3.8.0 2018-02-07
|
47
|
+
|
48
|
+
* Breaking Changes
|
49
|
+
* None
|
50
|
+
|
51
|
+
* Added
|
52
|
+
* [#582](https://github.com/binarylogic/authlogic/pull/582) Support rails 5.2
|
53
|
+
* [#583](https://github.com/binarylogic/authlogic/pull/583) Support openssl gem 2.0
|
54
|
+
|
55
|
+
* Fixed
|
56
|
+
* None
|
57
|
+
|
58
|
+
## 3.7.0 2018-02-07
|
59
|
+
|
60
|
+
* Breaking Changes
|
61
|
+
* None
|
62
|
+
|
63
|
+
* Added
|
64
|
+
* [#580](https://github.com/binarylogic/authlogic/pull/580) Deprecated
|
65
|
+
`ActionController::Parameters`, will be removed in 4.0.0
|
66
|
+
|
67
|
+
* Fixed
|
68
|
+
* None
|
69
|
+
|
70
|
+
## 3.6.1 2017-09-30
|
71
|
+
|
72
|
+
* Breaking Changes
|
73
|
+
* None
|
74
|
+
|
75
|
+
* Added
|
76
|
+
* None
|
77
|
+
|
78
|
+
* Fixed
|
79
|
+
* Allow TLD up to 24 characters per
|
80
|
+
https://data.iana.org/TLD/tlds-alpha-by-domain.txt
|
81
|
+
* [#561](https://github.com/binarylogic/authlogic/issues/561)
|
82
|
+
authenticates_many now works with scope_cookies:true
|
83
|
+
|
84
|
+
## 3.6.0 2017-04-28
|
85
|
+
|
86
|
+
* Breaking Changes
|
87
|
+
* None
|
88
|
+
|
89
|
+
* Added
|
90
|
+
* Support rails 5.1
|
91
|
+
|
92
|
+
* Fixed
|
93
|
+
* ensure that login field validation uses correct locale (@sskirby)
|
94
|
+
|
95
|
+
## 3.5.0 2016-08-29
|
96
|
+
|
97
|
+
* new
|
98
|
+
* Rails 5.0 support! Thanks to all reporters and contributors.
|
99
|
+
|
100
|
+
* changes
|
101
|
+
* increased default minimum password length to 8 (@iainbeeston)
|
102
|
+
* bind parameters in where statement for rails 5 support
|
103
|
+
* change callback for rails 5 support
|
104
|
+
* converts the ActionController::Parameters to a Hash for rails 5 support
|
105
|
+
* check last_request_at_threshold even if last_request_at_update_allowed returns true (@rofreg)
|
106
|
+
|
107
|
+
## 3.4.6 2015
|
108
|
+
|
109
|
+
* changes
|
110
|
+
* add Regex.email_nonascii for validation of emails w/unicode (@rchekaluk)
|
111
|
+
* allow scrypt 2.x (@jaredbeck)
|
112
|
+
|
113
|
+
## 3.4.5 2015-03-01
|
114
|
+
|
115
|
+
* changes
|
116
|
+
* security-hardening fix and cleanup in persistence_token lookup
|
117
|
+
* security-hardening fix in perishable_token lookup (thx @tomekr)
|
118
|
+
|
119
|
+
## 3.4.4 2014-12-23
|
120
|
+
|
121
|
+
* changes
|
122
|
+
* extract rw_config into an Authlogic::Config module
|
123
|
+
* improved the way config changes are made in tests
|
124
|
+
* fix for Rails 4.2 by extending ActiveModel
|
125
|
+
|
126
|
+
## 3.4.3 2014-10-08
|
127
|
+
|
128
|
+
* changes
|
129
|
+
* backfill CHANGELOG
|
130
|
+
* better compatibility with jruby (thx @petergoldstein)
|
131
|
+
* added scrypt as a dependency
|
132
|
+
* cleanup some code (thx @roryokane)
|
133
|
+
* reference 'bcrypt' gem instead of 'bcrypt-ruby' (thx @roryokane)
|
134
|
+
* fixed typo (thx @chamini2)
|
135
|
+
* fixed magic column validations for Rails 4.2 (thx @tom-kuca)
|
136
|
+
|
137
|
+
## 3.4.2 2014-04-28
|
138
|
+
|
139
|
+
* changes
|
140
|
+
* fixed the missing scrypt/bcrypt gem errors introduced in 3.4.1
|
141
|
+
* implemented autoloading for providers
|
142
|
+
* added longer subdomain support in email regex
|
143
|
+
|
144
|
+
## 3.4.1 2014-04-04
|
145
|
+
|
146
|
+
* changes
|
147
|
+
* undid an accidental revert of some code
|
148
|
+
|
149
|
+
## 3.4.0 2014-03-03
|
150
|
+
|
151
|
+
* Breaking Changes
|
152
|
+
* made scrypt the default crypto provider from SHA512
|
153
|
+
(https://github.com/binarylogic/authlogic#upgrading-to-authlogic-340)
|
154
|
+
See UPGRADING.md.
|
155
|
+
|
156
|
+
* Added
|
157
|
+
* officially support rails 4 (still supporting rails 3)
|
158
|
+
* added cookie signing
|
159
|
+
* added request store for better concurency for threaded environments
|
160
|
+
* added a rack adapter for Rack middleware support
|
161
|
+
|
162
|
+
* Fixed
|
163
|
+
* ditched appraisal
|
164
|
+
* improved find_with_case default performance
|
165
|
+
* added travis ci support
|
166
|
+
|
167
|
+
## 3.3.0 2014-04-04
|
168
|
+
|
169
|
+
* changes
|
170
|
+
* added safeguard against a sqli that was also fixed in rails 3.2.10/3.1.9/3.0.18
|
171
|
+
* imposed the bcrypt gem's mincost
|
172
|
+
* removed shoulda macros
|
173
|
+
|
174
|
+
## 3.2.0 2012-12-07
|
175
|
+
|
176
|
+
* new
|
177
|
+
* scrypt support
|
178
|
+
|
179
|
+
* changes
|
180
|
+
* moved back to LOWER for find_with_case ci lookups
|
181
|
+
|
182
|
+
## 3.1.3 2012-06-13
|
183
|
+
|
184
|
+
* changes
|
185
|
+
* removed jeweler
|
186
|
+
|
187
|
+
## 3.1.2 2012-06-01
|
188
|
+
|
189
|
+
* changes
|
190
|
+
* mostly test fixes
|
191
|
+
|
192
|
+
## 3.1.1 2012-06-01
|
193
|
+
|
194
|
+
* changes
|
195
|
+
* mostly doc fixes
|
196
|
+
|
197
|
+
## 3.1.0 2011-10-19
|
198
|
+
|
199
|
+
* changes
|
200
|
+
* mostly small bug fixes
|
201
|
+
|
202
|
+
## 3.0.3 2011-05-17
|
203
|
+
|
204
|
+
* changes
|
205
|
+
* rails 3.1 support
|
206
|
+
|
207
|
+
* new
|
208
|
+
* http auth support
|
209
|
+
|
210
|
+
## 3.0.2 2011-04-30
|
211
|
+
|
212
|
+
* changes
|
213
|
+
* doc fixes
|
214
|
+
|
215
|
+
## 3.0.1 2011-04-30
|
216
|
+
|
217
|
+
* changes
|
218
|
+
* switch from LOWER to LIKE for find_with_case ci lookups
|
219
|
+
|
220
|
+
## 3.0.0 2011-04-30
|
221
|
+
|
222
|
+
* new
|
223
|
+
* ssl cookie support
|
224
|
+
* httponly cookie support
|
225
|
+
* added a session generator
|
226
|
+
|
227
|
+
* changes
|
228
|
+
* rails 3 support
|
229
|
+
* ruby 1.9.2 support
|
data/CONTRIBUTING.md
CHANGED
@@ -25,13 +25,23 @@ Please ask usage questions on
|
|
25
25
|
|
26
26
|
## Development
|
27
27
|
|
28
|
+
Most local development should be done using the oldest supported version of
|
29
|
+
ruby. See `required_ruby_version` in the gemspec.
|
30
|
+
|
28
31
|
### Testing
|
29
32
|
|
30
|
-
Tests can be
|
33
|
+
Tests can be run against different versions of Rails like so:
|
34
|
+
|
35
|
+
```
|
36
|
+
BUNDLE_GEMFILE=test/gemfiles/Gemfile.rails-4.2.x bundle install
|
37
|
+
BUNDLE_GEMFILE=test/gemfiles/Gemfile.rails-4.2.x bundle exec rake
|
38
|
+
```
|
39
|
+
|
40
|
+
To run a single test:
|
31
41
|
|
32
42
|
```
|
33
|
-
BUNDLE_GEMFILE=test/gemfiles/Gemfile.rails-
|
34
|
-
|
43
|
+
BUNDLE_GEMFILE=test/gemfiles/Gemfile.rails-4.2.x \
|
44
|
+
bundle exec ruby –I test path/to/test.rb
|
35
45
|
```
|
36
46
|
|
37
47
|
### Linting
|
@@ -53,8 +63,8 @@ BUNDLE_GEMFILE=test/gemfiles/Gemfile.rails-3.2.x bundle exec rake test
|
|
53
63
|
|
54
64
|
1. Update version number in gemspec
|
55
65
|
1. Add release date to changelog entry
|
56
|
-
1. Commit
|
57
|
-
1. git tag -a -m "v3.6.0" "v3.6.0"
|
66
|
+
1. Commit with message like "Release 3.6.0"
|
67
|
+
1. git tag -a -m "v3.6.0" "v3.6.0" # or whatever number
|
58
68
|
1. git push --tags origin 3-stable # or whatever branch
|
59
69
|
1. gem build authlogic.gemspec
|
60
70
|
1. gem push authlogic-3.6.0
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,56 @@
|
|
1
1
|
# Authlogic
|
2
2
|
|
3
|
-
|
3
|
+
A clean, simple, and unobtrusive ruby authentication solution.
|
4
4
|
|
5
|
-
[![Gem Version]
|
6
|
-
[](https://travis-ci.org/binarylogic/authlogic)
|
7
|
-
[](https://codeclimate.com/github/binarylogic/authlogic)
|
5
|
+
[![Gem Version][5]][6] [![Build Status][1]][2] [![Code Climate][7]][8] [![Dependency Status][3]][4]
|
8
6
|
|
9
|
-
|
7
|
+
## Sponsors
|
10
8
|
|
11
|
-
|
9
|
+
[](https://timber.io?utm_source=github&utm_medium=authlogic)
|
10
|
+
|
11
|
+
[Tail Authlogic users](https://timber.io/docs/app/console/tail-a-user) in your logs!
|
12
|
+
|
13
|
+
## Documentation
|
14
|
+
|
15
|
+
| Version | Documentation |
|
16
|
+
| ----------- | ------------- |
|
17
|
+
| Unreleased | https://github.com/binarylogic/authlogic/blob/master/README.md |
|
18
|
+
| 3.7.0 | https://github.com/binarylogic/authlogic/blob/v3.7.0/README.md |
|
19
|
+
| 2.1.11 | https://github.com/binarylogic/authlogic/blob/v2.1.11/README.rdoc |
|
20
|
+
| 1.4.3 | https://github.com/binarylogic/authlogic/blob/v1.4.3/README.rdoc |
|
21
|
+
|
22
|
+
## Table of Contents
|
23
|
+
|
24
|
+
- [1. Introduction](#1-introduction)
|
25
|
+
- [1.a. Compatibility](#1a-compatibility)
|
26
|
+
- [1.b. Overview](#1b-overview)
|
27
|
+
- [1.c. Reference Documentation](#1c-reference-documentation)
|
28
|
+
- [2. Rails](#2-rails)
|
29
|
+
- [2.a. The users table](#2a-the-users-table)
|
30
|
+
- [2.b. Controller](#2b-controller)
|
31
|
+
- [2.c. View](#2c-view)
|
32
|
+
- [2.d. CSRF Protection](#2d-csrf-protection)
|
33
|
+
- [3. Testing](#3-testing)
|
34
|
+
- [4. Helpful links](#4-helpful-links)
|
35
|
+
- [5. Add-ons](#5-add-ons)
|
36
|
+
- [6. Internals](#6-internals)
|
37
|
+
|
38
|
+
## 1. Introduction
|
39
|
+
|
40
|
+
### 1.a. Compatibility
|
41
|
+
|
42
|
+
| Version | branches | tag | ruby | activerecord |
|
43
|
+
| ---------- | ---------------- | ------- | -------- | ------------- |
|
44
|
+
| Unreleased | master, 4-stable | | >= 2.2.0 | >= 4.2, < 5.3 |
|
45
|
+
| 3 | 3-stable | v3.6.0 | >= 1.9.3 | >= 3.2, < 5.2 |
|
46
|
+
| 2 | rails2 | v2.1.11 | >= 1.9.3 | ~> 2.3.0 |
|
47
|
+
| 1 | ? | v1.4.3 | ? | ? |
|
48
|
+
|
49
|
+
### 1.b. Overview
|
50
|
+
|
51
|
+
Authlogic introduces a new type of model. You can have as many as you want, and
|
52
|
+
name them whatever you want, just like your other models. In this example, we
|
53
|
+
want to authenticate with our `User` model, which is inferred from the name:
|
12
54
|
|
13
55
|
```ruby
|
14
56
|
class UserSession < Authlogic::Session::Base
|
@@ -44,7 +86,8 @@ You can also log out (i.e. **destroying** the session):
|
|
44
86
|
session.destroy
|
45
87
|
```
|
46
88
|
|
47
|
-
After a session has been created, you can persist it (i.e. **finding** the
|
89
|
+
After a session has been created, you can persist it (i.e. **finding** the
|
90
|
+
record) across requests. Thus keeping the user logged in:
|
48
91
|
|
49
92
|
``` ruby
|
50
93
|
session = UserSession.find
|
@@ -60,9 +103,13 @@ class User < ActiveRecord::Base
|
|
60
103
|
end
|
61
104
|
```
|
62
105
|
|
63
|
-
This handles validations, etc. It is also "smart" in the sense that it if a
|
106
|
+
This handles validations, etc. It is also "smart" in the sense that it if a
|
107
|
+
login field is present it will use that to authenticate, if not it will look for
|
108
|
+
an email field, etc. This is all configurable, but for 99% of cases that above
|
109
|
+
is all you will need to do.
|
64
110
|
|
65
|
-
You may specify how passwords are cryptographically hashed (or encrypted) by
|
111
|
+
You may specify how passwords are cryptographically hashed (or encrypted) by
|
112
|
+
setting the Authlogic::CryptoProvider option:
|
66
113
|
|
67
114
|
``` ruby
|
68
115
|
c.crypto_provider = Authlogic::CryptoProviders::BCrypt
|
@@ -74,74 +121,64 @@ You may validate international email addresses by enabling the provided alternat
|
|
74
121
|
c.validates_format_of_email_field_options = {:with => Authlogic::Regex.email_nonascii}
|
75
122
|
```
|
76
123
|
|
77
|
-
Also, sessions are automatically maintained. You can switch this on and off with
|
124
|
+
Also, sessions are automatically maintained. You can switch this on and off with
|
125
|
+
configuration, but the following will automatically log a user in after a
|
126
|
+
successful registration:
|
78
127
|
|
79
128
|
``` ruby
|
80
129
|
User.create(params[:user])
|
81
130
|
```
|
82
131
|
|
83
|
-
|
132
|
+
You can switch this on and off with the following configuration:
|
84
133
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
If you never set a crypto_provider and are upgrading, your passwords will break unless you set the original:
|
92
|
-
|
93
|
-
``` ruby
|
94
|
-
c.crypto_provider = Authlogic::CryptoProviders::Sha512
|
134
|
+
```ruby
|
135
|
+
class User < ActiveRecord::Base
|
136
|
+
acts_as_authentic do |c|
|
137
|
+
c.log_in_after_create = false
|
138
|
+
end # the configuration block is optional
|
139
|
+
end
|
95
140
|
```
|
96
141
|
|
97
|
-
|
142
|
+
Authlogic also updates the session when the user changes his/her password. You can also switch this on and off with the following configuration:
|
98
143
|
|
99
144
|
```ruby
|
100
|
-
|
101
|
-
|
145
|
+
class User < ActiveRecord::Base
|
146
|
+
acts_as_authentic do |c|
|
147
|
+
c.log_in_after_password_change = false
|
148
|
+
end # the configuration block is optional
|
149
|
+
end
|
102
150
|
```
|
103
151
|
|
104
|
-
|
152
|
+
Authlogic is very flexible, it has a strong public API and a plethora of hooks
|
153
|
+
to allow you to modify behavior and extend it. Check out the helpful links below
|
154
|
+
to dig deeper.
|
105
155
|
|
106
|
-
|
107
|
-
* <b>Repository:</b> http://github.com/binarylogic/authlogic/tree/master
|
108
|
-
* <b>Railscasts Screencast:</b> http://railscasts.com/episodes/160-authlogic
|
109
|
-
* <b>Example repository with tutorial in README:</b> http://github.com/binarylogic/authlogic_example/tree/master
|
110
|
-
* <b>Tutorial: Reset passwords with Authlogic the RESTful way:</b> http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic
|
111
|
-
* <b>Tutorial</b>: Rails Authentication with Authlogic http://www.sitepoint.com/rails-authentication-with-authlogic
|
112
|
-
* <b>Issues:</b> http://github.com/binarylogic/authlogic/issues
|
113
|
-
|
114
|
-
## Authlogic "add ons"
|
115
|
-
|
116
|
-
* <b>Authlogic OpenID addon:</b> http://github.com/binarylogic/authlogic_openid
|
117
|
-
* <b>Authlogic LDAP addon:</b> http://github.com/binarylogic/authlogic_ldap
|
118
|
-
* <b>Authlogic Facebook Connect:</b> http://github.com/kalasjocke/authlogic_facebook_connect
|
119
|
-
* <b>Authlogic Facebook Connect (New JS API):</b> http://github.com/studybyte/authlogic_facebook_connect
|
120
|
-
* <b>Authlogic Facebook Shim</b> http://github.com/james2m/authlogic_facebook_shim
|
121
|
-
* <b>Authlogic OAuth (Twitter):</b> http://github.com/jrallison/authlogic_oauth
|
122
|
-
* <b>Authlogic Oauth and OpenID:</b> http://github.com/viatropos/authlogic-connect
|
123
|
-
* <b>Authlogic PAM:</b> http://github.com/nbudin/authlogic_pam
|
124
|
-
* <b>Authlogic x509:</b> http://github.com/auth-scc/authlogic_x509
|
156
|
+
### 1.c. Reference Documentation
|
125
157
|
|
126
|
-
|
158
|
+
This README is just an introduction, but we also have [reference
|
159
|
+
documentation](http://www.rubydoc.info/github/binarylogic/authlogic).
|
127
160
|
|
128
|
-
|
161
|
+
**To use the reference documentation, you must understand how Authlogic's
|
162
|
+
code is organized.** There are 2 models, your Authlogic model and your
|
163
|
+
ActiveRecord model:
|
129
164
|
|
130
|
-
|
165
|
+
1. **Authlogic::Session**, your session models that
|
166
|
+
extend `Authlogic::Session::Base`.
|
167
|
+
2. **Authlogic::ActsAsAuthentic**, which adds in functionality to your
|
168
|
+
ActiveRecord model when you call `acts_as_authentic`.
|
131
169
|
|
132
|
-
|
170
|
+
Each of the above has various modules that are organized by topic: passwords,
|
171
|
+
cookies, etc. For example, if you want to timeout users after a certain period
|
172
|
+
of inactivity, you would look in `Authlogic::Session::Timeout`.
|
133
173
|
|
134
|
-
|
135
|
-
2. <b>Authlogic::ActsAsAuthentic</b>, which adds in functionality to your ActiveRecord model when you call acts_as_authentic.
|
174
|
+
## 2. Rails
|
136
175
|
|
137
|
-
|
176
|
+
Let's walk through a typical rails setup.
|
138
177
|
|
139
|
-
|
140
|
-
|
141
|
-
## Example migration
|
178
|
+
### 2.a. The users table
|
142
179
|
|
143
180
|
If you want to enable all the features of Authlogic, a migration to create a
|
144
|
-
|
181
|
+
`User` model might look like this:
|
145
182
|
|
146
183
|
``` ruby
|
147
184
|
class CreateUser < ActiveRecord::Migration
|
@@ -156,12 +193,15 @@ class CreateUser < ActiveRecord::Migration
|
|
156
193
|
|
157
194
|
# Authlogic::ActsAsAuthentic::PersistenceToken
|
158
195
|
t.string :persistence_token
|
196
|
+
t.index :persistence_token, unique: true
|
159
197
|
|
160
198
|
# Authlogic::ActsAsAuthentic::SingleAccessToken
|
161
199
|
t.string :single_access_token
|
200
|
+
t.index :single_access_token, unique: true
|
162
201
|
|
163
202
|
# Authlogic::ActsAsAuthentic::PerishableToken
|
164
203
|
t.string :perishable_token
|
204
|
+
t.index :perishable_token, unique: true
|
165
205
|
|
166
206
|
# Authlogic::Session::MagicColumns
|
167
207
|
t.integer :login_count, default: 0, null: false
|
@@ -183,15 +223,9 @@ class CreateUser < ActiveRecord::Migration
|
|
183
223
|
end
|
184
224
|
```
|
185
225
|
|
186
|
-
|
226
|
+
### 2.b. Controller
|
187
227
|
|
188
|
-
|
189
|
-
|
190
|
-
``` ruby
|
191
|
-
UserSession.create(params[:user_session])
|
192
|
-
```
|
193
|
-
|
194
|
-
What if your user sessions controller could look just like your other controllers...
|
228
|
+
Your sessions controller will look just like your other controllers.
|
195
229
|
|
196
230
|
```ruby
|
197
231
|
class UserSessionsController < ApplicationController
|
@@ -200,7 +234,7 @@ class UserSessionsController < ApplicationController
|
|
200
234
|
end
|
201
235
|
|
202
236
|
def create
|
203
|
-
@user_session = UserSession.new(
|
237
|
+
@user_session = UserSession.new(user_session_params)
|
204
238
|
if @user_session.save
|
205
239
|
redirect_to account_url
|
206
240
|
else
|
@@ -212,10 +246,37 @@ class UserSessionsController < ApplicationController
|
|
212
246
|
current_user_session.destroy
|
213
247
|
redirect_to new_user_session_url
|
214
248
|
end
|
249
|
+
|
250
|
+
private
|
251
|
+
|
252
|
+
def user_session_params
|
253
|
+
params.require(:user_session).permit(:email, :password, :remember_me)
|
254
|
+
end
|
215
255
|
end
|
216
256
|
```
|
217
257
|
|
218
|
-
As you can see, this fits nicely into the
|
258
|
+
As you can see, this fits nicely into the [conventional controller methods][9].
|
259
|
+
|
260
|
+
#### 2.b.1. Helper Methods
|
261
|
+
|
262
|
+
```ruby
|
263
|
+
class ApplicationController
|
264
|
+
helper_method :current_user_session, :current_user
|
265
|
+
|
266
|
+
private
|
267
|
+
def current_user_session
|
268
|
+
return @current_user_session if defined?(@current_user_session)
|
269
|
+
@current_user_session = UserSession.find
|
270
|
+
end
|
271
|
+
|
272
|
+
def current_user
|
273
|
+
return @current_user if defined?(@current_user)
|
274
|
+
@current_user = current_user_session && current_user_session.user
|
275
|
+
end
|
276
|
+
end
|
277
|
+
```
|
278
|
+
|
279
|
+
### 2.c. View
|
219
280
|
|
220
281
|
```erb
|
221
282
|
<%= form_for @user_session do |f| %>
|
@@ -239,32 +300,18 @@ As you can see, this fits nicely into the RESTful development pattern. What abou
|
|
239
300
|
<% end %>
|
240
301
|
```
|
241
302
|
|
242
|
-
|
303
|
+
### 2.d. CSRF Protection
|
243
304
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
private
|
249
|
-
def current_user_session
|
250
|
-
return @current_user_session if defined?(@current_user_session)
|
251
|
-
@current_user_session = UserSession.find
|
252
|
-
end
|
253
|
-
|
254
|
-
def current_user
|
255
|
-
return @current_user if defined?(@current_user)
|
256
|
-
@current_user = current_user_session && current_user_session.user
|
257
|
-
end
|
258
|
-
end
|
259
|
-
```
|
305
|
+
Because Authlogic introduces its own methods for storing user sessions, the CSRF
|
306
|
+
(Cross Site Request Forgery) protection that is built into Rails will not work
|
307
|
+
out of the box.
|
260
308
|
|
261
|
-
|
309
|
+
No generally applicable mitigation by the authlogic library is possible, because
|
310
|
+
the instance variable you use to store a reference to the user session in `def
|
311
|
+
current_user_session` will not be known to authlogic.
|
262
312
|
|
263
|
-
|
264
|
-
|
265
|
-
No generally applicable mitigation by the authlogic library is possible, because the instance variable you use to store a reference to the user session in `def current_user_session` will not be known to authlogic.
|
266
|
-
|
267
|
-
You will need to override `ActionController::Base#handle_unverified_request` to do something appropriate to how your app handles user sessions, e.g.:
|
313
|
+
You will need to override `ActionController::Base#handle_unverified_request` to
|
314
|
+
do something appropriate to how your app handles user sessions, e.g.:
|
268
315
|
|
269
316
|
```ruby
|
270
317
|
class ApplicationController < ActionController::Base
|
@@ -283,12 +330,57 @@ class ApplicationController < ActionController::Base
|
|
283
330
|
end
|
284
331
|
```
|
285
332
|
|
286
|
-
## Testing
|
333
|
+
## 3. Testing
|
287
334
|
|
288
335
|
See [Authlogic::TestCase](https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/test_case.rb)
|
289
336
|
|
290
|
-
##
|
337
|
+
## 4. Helpful links
|
291
338
|
|
292
|
-
|
339
|
+
* <b>API Reference:</b> http://www.rubydoc.info/github/binarylogic/authlogic
|
340
|
+
* <b>Repository:</b> https://github.com/binarylogic/authlogic/tree/master
|
341
|
+
* <b>Railscasts Screencast:</b> http://railscasts.com/episodes/160-authlogic
|
342
|
+
* <b>Example repository with tutorial in README:</b> https://github.com/binarylogic/authlogic_example/tree/master
|
343
|
+
* <b>Tutorial</b>: Rails Authentication with Authlogic https://www.sitepoint.com/rails-authentication-with-authlogic
|
344
|
+
* <b>Issues:</b> https://github.com/binarylogic/authlogic/issues
|
345
|
+
* <b>Chrome is not logging out on browser close</b> https://productforums.google.com/forum/#!topic/chrome/9l-gKYIUg50/discussion
|
346
|
+
|
347
|
+
## 5. Add-ons
|
348
|
+
|
349
|
+
* <b>Authlogic OpenID addon:</b> https://github.com/binarylogic/authlogic_openid
|
350
|
+
* <b>Authlogic LDAP addon:</b> https://github.com/binarylogic/authlogic_ldap
|
351
|
+
* <b>Authlogic Facebook Connect:</b> https://github.com/kalasjocke/authlogic-facebook-connect
|
352
|
+
* <b>Authlogic Facebook Connect (New JS API):</b> https://github.com/studybyte/authlogic_facebook_connect
|
353
|
+
* <b>Authlogic Facebook Shim</b> https://github.com/james2m/authlogic_facebook_shim
|
354
|
+
* <b>Authlogic OAuth (Twitter):</b> https://github.com/jrallison/authlogic_oauth
|
355
|
+
* <b>Authlogic Oauth and OpenID:</b> https://github.com/lancejpollard/authlogic-connect
|
356
|
+
* <b>Authlogic PAM:</b> https://github.com/nbudin/authlogic_pam
|
357
|
+
* <b>Authlogic x509:</b> https://github.com/auth-scc/authlogic_x509
|
358
|
+
|
359
|
+
If you create one of your own, please let us know about it so we can add it to
|
360
|
+
this list. Or just fork the project, add your link, and send us a pull request.
|
361
|
+
|
362
|
+
## 6. Internals
|
363
|
+
|
364
|
+
Interested in how all of this all works? Think about an ActiveRecord model. A
|
365
|
+
database connection must be established before you can use it. In the case of
|
366
|
+
Authlogic, a controller connection must be established before you can use it. It
|
367
|
+
uses that controller connection to modify cookies, the current session, login
|
368
|
+
with HTTP basic, etc. It connects to the controller through a before filter that
|
369
|
+
is automatically set in your controller which lets Authlogic know about the
|
370
|
+
current controller object. Then Authlogic leverages that to do everything, it's
|
371
|
+
a pretty simple design. Nothing crazy going on, Authlogic is just leveraging the
|
372
|
+
tools your framework provides in the controller object.
|
373
|
+
|
374
|
+
## Intellectual Property
|
293
375
|
|
294
376
|
Copyright (c) 2012 Ben Johnson of Binary Logic, released under the MIT license
|
377
|
+
|
378
|
+
[1]: https://api.travis-ci.org/binarylogic/authlogic.svg?branch=master
|
379
|
+
[2]: https://travis-ci.org/binarylogic/authlogic
|
380
|
+
[3]: https://gemnasium.com/badges/github.com/binarylogic/authlogic.svg
|
381
|
+
[4]: https://gemnasium.com/binarylogic/authlogic
|
382
|
+
[5]: https://badge.fury.io/rb/authlogic.png
|
383
|
+
[6]: http://badge.fury.io/rb/authlogic
|
384
|
+
[7]: https://codeclimate.com/github/binarylogic/authlogic.png
|
385
|
+
[8]: https://codeclimate.com/github/binarylogic/authlogic
|
386
|
+
[9]: http://guides.rubyonrails.org/routing.html#resource-routing-the-rails-default
|