authlogic 2.0.1 → 2.1.2
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.
- data/.gitignore +9 -0
- data/CHANGELOG.rdoc +110 -1
- data/{MIT-LICENSE → LICENSE} +1 -1
- data/README.rdoc +138 -161
- data/Rakefile +40 -19
- data/VERSION.yml +4 -0
- data/authlogic.gemspec +212 -0
- data/init.rb +1 -1
- data/lib/authlogic/acts_as_authentic/base.rb +44 -35
- data/lib/authlogic/acts_as_authentic/email.rb +47 -14
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +20 -14
- data/lib/authlogic/acts_as_authentic/login.rb +84 -8
- data/lib/authlogic/acts_as_authentic/password.rb +207 -88
- data/lib/authlogic/acts_as_authentic/perishable_token.rb +9 -4
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +4 -2
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +5 -4
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +16 -4
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +10 -3
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +1 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +13 -1
- data/lib/authlogic/controller_adapters/rails_adapter.rb +14 -4
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +61 -0
- data/lib/authlogic/crypto_providers/aes256.rb +2 -2
- data/lib/authlogic/crypto_providers/bcrypt.rb +3 -1
- data/lib/authlogic/crypto_providers/sha1.rb +2 -2
- data/lib/authlogic/i18n/translator.rb +15 -0
- data/lib/authlogic/i18n.rb +43 -14
- data/lib/authlogic/regex.rb +25 -0
- data/lib/authlogic/session/activation.rb +2 -0
- data/lib/authlogic/session/active_record_trickery.rb +26 -5
- data/lib/authlogic/session/brute_force_protection.rb +30 -11
- data/lib/authlogic/session/callbacks.rb +18 -7
- data/lib/authlogic/session/cookies.rb +21 -17
- data/lib/authlogic/session/existence.rb +6 -2
- data/lib/authlogic/session/foundation.rb +1 -1
- data/lib/authlogic/session/http_auth.rb +46 -11
- data/lib/authlogic/session/magic_columns.rb +29 -9
- data/lib/authlogic/session/magic_states.rb +6 -5
- data/lib/authlogic/session/params.rb +16 -10
- data/lib/authlogic/session/password.rb +115 -31
- data/lib/authlogic/session/priority_record.rb +1 -1
- data/lib/authlogic/session/session.rb +5 -3
- data/lib/authlogic/session/timeout.rb +1 -1
- data/lib/authlogic/session/validation.rb +13 -7
- data/lib/authlogic/test_case/mock_controller.rb +45 -0
- data/lib/authlogic/test_case/mock_cookie_jar.rb +14 -0
- data/lib/authlogic/test_case/mock_logger.rb +10 -0
- data/lib/authlogic/test_case/mock_request.rb +19 -0
- data/lib/authlogic/test_case/rails_request_adapter.rb +30 -0
- data/lib/authlogic/test_case.rb +114 -0
- data/lib/authlogic.rb +4 -3
- data/rails/init.rb +1 -0
- data/shoulda_macros/authlogic.rb +3 -2
- data/test/acts_as_authentic_test/base_test.rb +6 -0
- data/test/acts_as_authentic_test/email_test.rb +25 -7
- data/test/acts_as_authentic_test/login_test.rb +37 -7
- data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
- data/test/acts_as_authentic_test/password_test.rb +46 -44
- data/test/acts_as_authentic_test/perishable_token_test.rb +36 -2
- data/test/acts_as_authentic_test/restful_authentication_test.rb +40 -0
- data/test/acts_as_authentic_test/session_maintenance_test.rb +26 -18
- data/test/acts_as_authentic_test/single_access_test.rb +6 -1
- data/test/i18n_test.rb +33 -0
- data/test/libs/affiliate.rb +7 -0
- data/test/libs/ldaper.rb +3 -0
- data/test/random_test.rb +2 -2
- data/test/session_test/activation_test.rb +1 -1
- data/test/session_test/active_record_trickery_test.rb +12 -2
- data/test/session_test/brute_force_protection_test.rb +37 -12
- data/test/session_test/cookies_test.rb +3 -3
- data/test/session_test/existence_test.rb +3 -3
- data/test/session_test/http_auth_test.rb +20 -8
- data/test/session_test/magic_columns_test.rb +9 -6
- data/test/session_test/magic_states_test.rb +3 -3
- data/test/session_test/params_test.rb +4 -4
- data/test/session_test/password_test.rb +23 -1
- data/test/session_test/session_test.rb +9 -9
- data/test/session_test/timeout_test.rb +10 -1
- data/test/test_helper.rb +53 -23
- metadata +42 -27
- data/Manifest.txt +0 -111
- data/lib/authlogic/testing/test_unit_helpers.rb +0 -39
- data/lib/authlogic/version.rb +0 -56
- data/test/libs/mock_controller.rb +0 -35
- data/test/libs/mock_cookie_jar.rb +0 -10
- data/test/libs/mock_request.rb +0 -5
data/.gitignore
ADDED
data/CHANGELOG.rdoc
CHANGED
|
@@ -1,4 +1,113 @@
|
|
|
1
|
-
== 2.
|
|
1
|
+
== 2.1.2
|
|
2
|
+
|
|
3
|
+
* Return the newly create object for the class level create method, instead of a boolean
|
|
4
|
+
* Add a model_name class method for Authlogic::Session for rails 3 compatibility. Will be using ActiveModel eventually, but this should be a quick fix.
|
|
5
|
+
|
|
6
|
+
== 2.1.1 released 2009-7-04
|
|
7
|
+
|
|
8
|
+
* Use mb_chars when downcasing the login string to support international characters.
|
|
9
|
+
* Check for the existence of the :remember_me key before setting remember_me off of a hash.
|
|
10
|
+
* Added check to make sure Authlogic is not loaded too late, causing a NotActivated error.
|
|
11
|
+
|
|
12
|
+
== 2.1.0 released 2009-6-27
|
|
13
|
+
|
|
14
|
+
* Fixed bug when using act_like_restful_authentication and setting passwords, needed to add a 2nd parameter to tell if to check against the database or not.
|
|
15
|
+
* Don't save record if they are read only.
|
|
16
|
+
|
|
17
|
+
== 2.0.14 released 2009-6-13
|
|
18
|
+
|
|
19
|
+
* Fixed issue with using brute force protection AND generalize_credentials_error_messages. Brute force protection was looking to see if there were password errors, which generalize_credentials_error_messages was obfuscating.
|
|
20
|
+
* Added db_setup? method to avoid errors during rake tasks where the db might not be set up. Ex: migrations
|
|
21
|
+
* Stop using errors.on(key) since that is now deprecated in Rails. Use errors[key] instead.
|
|
22
|
+
* Use valid_password? for the method name to validate a password instead of valid_#{password_field}?.
|
|
23
|
+
|
|
24
|
+
== 2.0.13 released 2009-5-13
|
|
25
|
+
|
|
26
|
+
* Add authlogic/regex.rb to manifest
|
|
27
|
+
|
|
28
|
+
== 2.0.12 released 2009-5-13
|
|
29
|
+
|
|
30
|
+
* Added the ability to add a last_request_update_allowed? method in your controller to pragmatically tell Authlogic when and when not to update the last_request_at field in your database. This only takes effect if the method if present.
|
|
31
|
+
* Extracted Authlogic's regular expressions into it's own module to allow easy use of them outside of Authlogic. See Authlogic::Regex for more info.
|
|
32
|
+
* Made being_brute_force_protected? true for the Authlogic::Session::BruteForceProtection module.
|
|
33
|
+
* Added the configuration option generalize_credentials_error_messages for the Authlogic::Session::Password module. This allows you to generalize your login / password errors messages as to not reveal was the problem was when authenticating. If enabled, when an invalid login is supplied it will use the same exact error message when an invalid password is supplied.
|
|
34
|
+
* Update email regular expression to use A-Z0-9 instead of /w as to not allow for diacritical marks in an email address.
|
|
35
|
+
* Changed config() convenience method to rw_config() to be more descriptive and less vague.
|
|
36
|
+
|
|
37
|
+
== 2.0.11 released 2009-4-25
|
|
38
|
+
|
|
39
|
+
* Fix bug when password is turned off and the SingleAccessToken module calls the after_password_set callback.
|
|
40
|
+
* HTTP basic auth can now be toggled on or off. It also checks for the existence of a standard username and password before enabling itself.
|
|
41
|
+
* Added option check_passwords_against_database for Authlogic::ActsAsAuthentic::Password to toggle between checking the password against the database value or the object value. Also added the same functionality to the instance method: valid_password?("password", true), where the second argument tells Authlogic to check the password against the database value. The default for this new feature is true.
|
|
42
|
+
* Add a maintain_sessions configuration option to Authlogic::ActsAsAuthentic::SessionMaintenance as a "clearer" option to disable automatic session maintenance.
|
|
43
|
+
* single_access_allowed_request_types can also be equal to :all instead of just [:all].
|
|
44
|
+
* Refactor params_enabled? so that the single_access_allowed? method in controllers takes precedence.
|
|
45
|
+
* Added testing comments in the README and expanded on the documentation in Authlogic::TestCase
|
|
46
|
+
|
|
47
|
+
== 2.0.10 released 2009-4-21
|
|
48
|
+
|
|
49
|
+
* Mock request is now transparent to non existent methods. Since the methods calls really have no functional value when testing authlogic.
|
|
50
|
+
* Allow password confirmation to be disabled.
|
|
51
|
+
* Modified login format validation to allow for the + character since emails addresses allow that as a valid character.
|
|
52
|
+
* Added merge_* configuration methods for acts_as_authentic to make merging options into configuration options that default to hashes. Just a few convenience methods.
|
|
53
|
+
|
|
54
|
+
== 2.0.9 released 2009-4-9
|
|
55
|
+
|
|
56
|
+
* Fixed bug where hooks provided by the password module were called when the password module was not being used due to the fact that the password field did not exist.
|
|
57
|
+
* Fixed bug where the find_with_login method was not being aliased if you were using an alternate field besides login.
|
|
58
|
+
|
|
59
|
+
== 2.0.8 release 2009-4-9
|
|
60
|
+
|
|
61
|
+
* Dont reset the @password_changed instance variable to false because its halts the callback chain, instead reset it to nil.
|
|
62
|
+
|
|
63
|
+
== 2.0.7 released 2009-4-9
|
|
64
|
+
|
|
65
|
+
* Rename TestCase::ControllerAdapter to TestCase::RailsRequestAdapter to help clarify it's usage and fix a constant typo.
|
|
66
|
+
|
|
67
|
+
== 2.0.6 released 2009-4-9
|
|
68
|
+
|
|
69
|
+
* Don't use second, use [1] instead so older rails versions don't complain.
|
|
70
|
+
* Update email regular expression to be less TLD specific: (?:[A-Z]{2,4}|museum|travel)
|
|
71
|
+
* Update shoulda macro for 2.0
|
|
72
|
+
* validates_length_of_password_confirmation_field_options defaults to validates_confirmation_of_password_field_options
|
|
73
|
+
* Use MockCookieJar in tests instead of a Hash in the MockController.
|
|
74
|
+
* Cookies now store the record id as well, for faster lookup. Also to avoid the need to use sessions since sessions are lazily loaded in rails 2.3+
|
|
75
|
+
* Add configuration option for Authlogic::ActsAsAuthentic: ignore_blank_passwords
|
|
76
|
+
* Fix cookie_domain in rails adapter
|
|
77
|
+
* Make password and login fields optional. This allows you to have an alternate authentication method as your main authentication source. Such as OpenID, LDAP, or whatever you want.
|
|
78
|
+
* Reset the @password_changed instance variable after the record has been saved.
|
|
79
|
+
* Add referer and user_agent to mock requests for testing purposes.
|
|
80
|
+
* Add :case_sensitive => false to validates_uniqueness_of calls on the login and email fields.
|
|
81
|
+
* MockRequest not tries to use controller.env['REMOTE_ADDR'] for the IP address in tests.
|
|
82
|
+
* Add in custom find_with_email and find_with_login methods to perform case insensitive searches for databases that are case sensitive by default. This is only done if the :case_insensitive option for validates_uniqueness_of_login_field_options or validates_uniqueness_of_email_field_options is set to false. Which, as of this version, it is. If you are using MySQL this has been the default behavior all along. If you are using SQLite or Postgres this has NOT been the default behavior.
|
|
83
|
+
* Added in exception explaining that you are using the old configuration for acts_as_authentic with an example of the new format.
|
|
84
|
+
|
|
85
|
+
== 2.0.5 released 2009-3-30
|
|
86
|
+
|
|
87
|
+
* Stub out authenticate_with_http_basic for TestCase::ControllerAdapter.
|
|
88
|
+
* Added second parameter for add_acts_as_authentic module to specify the position: append or prepend.
|
|
89
|
+
|
|
90
|
+
== 2.0.4 released 2009-3-28
|
|
91
|
+
|
|
92
|
+
* Added validates_uniqueness_of_login_field_options and validates_uniqueness_of_email_field_options configuration options
|
|
93
|
+
* Add in checks to make sure session_class is not nil.
|
|
94
|
+
* Cleaned up TestCase some more and added functionality to log users in during functional tests.
|
|
95
|
+
|
|
96
|
+
== 2.0.3 released 2009-3-26
|
|
97
|
+
|
|
98
|
+
* Fixed error where default session class does not exist.
|
|
99
|
+
* Fixed human_name for the model to use its own human name and not delegate to the associated model. Translation should be under authlogic.models.user_session (or whatever the name of your session is).
|
|
100
|
+
* Fixed human_attribute_name to use Authlogic keys for translation instead of ActiveRecord: authlogic.attributes.user_session.login
|
|
101
|
+
* For transitioning from restful_authentication, set the REST_AUTH_SITE_KEY to '' if it doesn't exist, instead of nil.
|
|
102
|
+
* Completely rewrote Authlogic::Testing, it's now called Authlogic::TestCase. Testing Authlogic is much easier now. Please see Authlogic::TestCase for more info.
|
|
103
|
+
|
|
104
|
+
== 2.0.2 released 2009-3-24
|
|
105
|
+
|
|
106
|
+
* Reset failed_login_count if consecutive_failed_logins_limit has been exceed and the failed_login_ban_for has passed.
|
|
107
|
+
* Update test helpers to use the new configuration scheme.
|
|
108
|
+
* Fixed issue when logging doesn't update last_request_at, so the next persistence try would fail.
|
|
109
|
+
|
|
110
|
+
== 2.0.1 released 2009-3-23
|
|
2
111
|
|
|
3
112
|
* Validate length of password.
|
|
4
113
|
* Dont save sessions with a ! during session maintenance.
|
data/{MIT-LICENSE → LICENSE}
RENAMED
data/README.rdoc
CHANGED
|
@@ -2,93 +2,142 @@
|
|
|
2
2
|
|
|
3
3
|
Authlogic is a clean, simple, and unobtrusive ruby authentication solution.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
A code example can replace a thousand words...
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
2. It ties everything together on the domain level. Take a new user registration for example, no reason to manually log the user in, authlogic handles this for you via callbacks. The same applies to a user changing their password. Authlogic handles maintaining the session for you.
|
|
9
|
-
3. Your application can stay clean and focused and free of redundant authentication code from app to app. Meaning generators are *NOT* necessary at all.
|
|
10
|
-
4. A byproduct of #3 is that you don't have to test the same code over and over in each of your apps. You don't test the internals of ActiveRecord in each of your apps, so why would you test the internals of Authlogic? It's already been thoroughly tested for you. Focus on your application, and get rid of the noise by testing your application specific code and not generated code that you didn't write.
|
|
11
|
-
5. You get to write your own code, just like you do for any other model. Meaning the code you write is specific to your application, the way you want it, and more importantly you understand it.
|
|
12
|
-
6. You are not restricted to a single session. Think about Apple's me.com, where they need you to authenticate a second time before changing your billing information. Why not just create a second session for this? It works just like your initial session. Then your billing controller can require an "ultra secure" session.
|
|
7
|
+
Authlogic introduces a new type of model. You can have as many as you want, and name them whatever you want, just like your other models. In this example, we want to authenticate with the User model, which is inferred by the name:
|
|
13
8
|
|
|
14
|
-
|
|
9
|
+
class UserSession < Authlogic::Session::Base
|
|
10
|
+
# specify configuration here, such as:
|
|
11
|
+
# logout_on_timeout true
|
|
12
|
+
# ...many more options in the documentation
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Log in with any of the following. Create a UserSessionsController and use it just like your other models:
|
|
16
|
+
|
|
17
|
+
UserSession.create(:login => "bjohnson", :password => "my password", :remember_me => true)
|
|
18
|
+
session = UserSession.new(:login => "bjohnson", :password => "my password", :remember_me => true); session.save
|
|
19
|
+
UserSession.create(:openid_identifier => "identifier", :remember_me => true) # requires the authlogic-oid "add on" gem
|
|
20
|
+
UserSession.create(my_user_object, true) # skip authentication and log the user in directly, the true means "remember me"
|
|
21
|
+
|
|
22
|
+
The above handles the entire authentication process for you. It first authenticates, then it sets up the proper session values and cookies to persist the session. Just like you would if you rolled your own authentication solution.
|
|
23
|
+
|
|
24
|
+
You can also log out / destroy the session:
|
|
25
|
+
|
|
26
|
+
session.destroy
|
|
27
|
+
|
|
28
|
+
After a session has been created, you can persist it across requests. Thus keeping the user logged in:
|
|
29
|
+
|
|
30
|
+
session = UserSession.find
|
|
31
|
+
|
|
32
|
+
To get all of the nice authentication functionality in your model just do this:
|
|
33
|
+
|
|
34
|
+
class User < ActiveRecord::Base
|
|
35
|
+
acts_as_authentic do |c|
|
|
36
|
+
c.my_config_option = my_value
|
|
37
|
+
end # the configuration block is optional
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
This handles validations, etc. It is also "smart" in the sense that it if a login field is present it will use that to authenticate, if not it will look for an email field, etc. This is all configurable, but for 99% of cases that above is all you will need to do.
|
|
41
|
+
|
|
42
|
+
Also, sessions are automatically maintained. You can switch this on and off with configuration, but the following will automatically log a user in after a successful registration:
|
|
43
|
+
|
|
44
|
+
User.create(params[:user])
|
|
45
|
+
|
|
46
|
+
This also updates the session when the user changes his/her password.
|
|
47
|
+
|
|
48
|
+
Authlogic is very flexible, it has a strong public API and a plethora of hooks to allow you to modify behavior and extend it. Check out the helpful links below to dig deeper.
|
|
15
49
|
|
|
16
50
|
== Helpful links
|
|
17
51
|
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* <b>Bugs / feature suggestions:</b> http://binarylogic.lighthouseapp.com/projects/18752-authlogic
|
|
52
|
+
* <b>Documentation:</b> http://rdoc.info/projects/binarylogic/authlogic
|
|
53
|
+
* <b>Repository:</b> http://github.com/binarylogic/authlogic/tree/master
|
|
54
|
+
* <b>Railscasts Screencast:</b> http://railscasts.com/episodes/160-authlogic
|
|
55
|
+
* <b>Live example with OpenID "add on":</b> http://authlogicexample.binarylogic.com
|
|
56
|
+
* <b>Live example repository with tutorial in README:</b> http://github.com/binarylogic/authlogic_example/tree/master
|
|
57
|
+
* <b>Tutorial: Reset passwords with Authlogic the RESTful way:</b> http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic
|
|
58
|
+
* <b>Issues:</b> http://github.com/binarylogic/authlogic/issues
|
|
26
59
|
* <b>Google group:</b> http://groups.google.com/group/authlogic
|
|
27
60
|
|
|
28
|
-
|
|
29
|
-
|
|
61
|
+
<b>Before contacting me directly, please read:</b>
|
|
62
|
+
|
|
63
|
+
If you find a bug or a problem please post it in the issues section. If you need help with something, please use google groups. I check both regularly and get emails when anything happens, so that is the best place to get help. This also benefits other people in the future with the same questions / problems. Thank you.
|
|
64
|
+
|
|
65
|
+
== Authlogic "add ons"
|
|
66
|
+
|
|
67
|
+
* <b>Authlogic OpenID addon:</b> http://github.com/binarylogic/authlogic_openid
|
|
68
|
+
* <b>Authlogic LDAP addon:</b> http://github.com/binarylogic/authlogic_ldap
|
|
69
|
+
* <b>Authlogic Facebook Connect:</b> http://github.com/kalasjocke/authlogic_facebook_connect
|
|
70
|
+
* <b>Authlogic OAuth (Twitter):</b> http://github.com/jrallison/authlogic_oauth
|
|
71
|
+
|
|
72
|
+
If you create one of your own, please let me know about it so I can add it to this list. Or just fork the project, add your link, and send me a pull request.
|
|
30
73
|
|
|
31
|
-
==
|
|
74
|
+
== Session bugs (please read if you are having issues with logging in / out)
|
|
32
75
|
|
|
33
|
-
|
|
76
|
+
Apparently there is a bug with apache / passenger for v2.1.X with sessions not working properly. This is most likely your problem if you are having trouble logging in / out. This is *not* an Authlogic issue. This can be solved by updating passener or using an alternative session store solution, such as active record store.
|
|
34
77
|
|
|
35
|
-
|
|
78
|
+
== Documentation explanation
|
|
36
79
|
|
|
37
|
-
|
|
38
|
-
2. Authlogic::ActsAsAuthentic, which adds in functionality to your ActiveRecord model.
|
|
80
|
+
You can find anything you want about Authlogic in the {documentation}[http://authlogic.rubyforge.org], all that you need to do is understand the basic design behind it.
|
|
39
81
|
|
|
40
|
-
|
|
82
|
+
That being said, there are 2 models involved during authentication. Your Authlogic model and your ActiveRecord model:
|
|
41
83
|
|
|
42
|
-
|
|
84
|
+
1. <b>Authlogic::Session</b>, your session models that extend Authlogic::Session::Base.
|
|
85
|
+
2. <b>Authlogic::ActsAsAuthentic</b>, which adds in functionality to your ActiveRecord model when you call acts_as_authentic.
|
|
86
|
+
|
|
87
|
+
Each of the above has its various sub modules that contain common logic. The sub modules are responsible for including *everything* related to it: configuration, class methods, instance methods, etc.
|
|
88
|
+
|
|
89
|
+
For example, if you want to timeout users after a certain period of inactivity, you would look in <b>Authlogic::Session::Timeout</b>. To help you out, I listed the following publicly relevant modules with short descriptions. For the sake of brevity, there are more modules than listed here, the ones not listed are more for internal use, but you can easily read up on them in the {documentation}[http://authlogic.rubyforge.org].
|
|
43
90
|
|
|
44
91
|
=== Authlogic::ActsAsAuthentic sub modules
|
|
45
92
|
|
|
46
|
-
These modules are for the
|
|
47
|
-
|
|
48
|
-
* Authlogic::ActsAsAuthentic::Base - Provides the acts_as_authentic class method and includes all of the submodules.
|
|
49
|
-
* Authlogic::ActsAsAuthentic::Email - Handles everything related to the email field.
|
|
50
|
-
* Authlogic::ActsAsAuthentic::LoggedInStatus - Provides handy named scopes and methods for determining if the user is logged in or out.
|
|
51
|
-
* Authlogic::ActsAsAuthentic::Login - Handles everything related to the login field.
|
|
52
|
-
* Authlogic::ActsAsAuthentic::MagicColumns - Handles everything related to the "magic" fields: login_count, failed_login_count, etc.
|
|
53
|
-
* Authlogic::ActsAsAuthentic::Password - This one is important. It handles encrypting your password, salting it, etc. It also has support for transitioning password algorithms.
|
|
54
|
-
* Authlogic::ActsAsAuthentic::PerishableToken - Handles maintaining the perishable token field, also provides a class level method for finding record using the token.
|
|
55
|
-
* Authlogic::ActsAsAuthentic::PersistenceToken - Handles maintaining the persistence token. This is the token stored in cookies and sessions to persist the users session.
|
|
56
|
-
* Authlogic::ActsAsAuthentic::RestfulAuthentication - Provides configuration options to easily migrate from the restful_authentication plugin.
|
|
57
|
-
* Authlogic::ActsAsAuthentic::SessionMaintenance - Handles
|
|
58
|
-
* Authlogic::ActsAsAuthentic::SingleAccessToken - Handles maintaining the single access token.
|
|
59
|
-
* Authlogic::ActsAsAuthentic::ValidationsScope - Allows you to scope validations, etc. Just like the :scope option for validates_uniqueness_of
|
|
93
|
+
These modules are for the ActiveRecord side of things, the models that call acts_as_authentic.
|
|
94
|
+
|
|
95
|
+
* <b>Authlogic::ActsAsAuthentic::Base</b> - Provides the acts_as_authentic class method and includes all of the submodules.
|
|
96
|
+
* <b>Authlogic::ActsAsAuthentic::Email</b> - Handles everything related to the email field.
|
|
97
|
+
* <b>Authlogic::ActsAsAuthentic::LoggedInStatus</b> - Provides handy named scopes and methods for determining if the user is logged in or out.
|
|
98
|
+
* <b>Authlogic::ActsAsAuthentic::Login</b> - Handles everything related to the login field.
|
|
99
|
+
* <b>Authlogic::ActsAsAuthentic::MagicColumns</b> - Handles everything related to the "magic" fields: login_count, failed_login_count, last_request_at, etc.
|
|
100
|
+
* <b>Authlogic::ActsAsAuthentic::Password</b> - This one is important. It handles encrypting your password, salting it, etc. It also has support for transitioning password algorithms.
|
|
101
|
+
* <b>Authlogic::ActsAsAuthentic::PerishableToken</b> - Handles maintaining the perishable token field, also provides a class level method for finding record using the token.
|
|
102
|
+
* <b>Authlogic::ActsAsAuthentic::PersistenceToken</b> - Handles maintaining the persistence token. This is the token stored in cookies and sessions to persist the users session.
|
|
103
|
+
* <b>Authlogic::ActsAsAuthentic::RestfulAuthentication</b> - Provides configuration options to easily migrate from the restful_authentication plugin.
|
|
104
|
+
* <b>Authlogic::ActsAsAuthentic::SessionMaintenance</b> - Handles automatic session maintenance. EX: a new user registers, automatically log them in. Or a user changes their password, update their session.
|
|
105
|
+
* <b>Authlogic::ActsAsAuthentic::SingleAccessToken</b> - Handles maintaining the single access token.
|
|
106
|
+
* <b>Authlogic::ActsAsAuthentic::ValidationsScope</b> - Allows you to scope all validations, etc. Just like the :scope option for validates_uniqueness_of
|
|
60
107
|
|
|
61
108
|
=== Authlogic::Session sub modules
|
|
62
109
|
|
|
63
|
-
These modules are for the
|
|
64
|
-
|
|
65
|
-
* Authlogic::Session::BruteForceProtection - Disables accounts after a certain number of consecutive failed
|
|
66
|
-
* Authlogic::Session::Callbacks - Your tools to extend
|
|
67
|
-
* Authlogic::Session::Cookies - Authentication via cookies.
|
|
68
|
-
* Authlogic::Session::Existence - Creating, saving, and destroying objects.
|
|
69
|
-
* Authlogic::Session::HttpAuth - Authentication via basic HTTP authentication.
|
|
70
|
-
* Authlogic::Session::Id - Allows sessions to be separated by an id, letting you have multiple sessions for a single user.
|
|
71
|
-
* Authlogic::Session::MagicColumns - Maintains "magic" database columns, similar to created_at and updated_at for ActiveRecord.
|
|
72
|
-
* Authlogic::Session::MagicStates - Automatically validates based on the records states: active
|
|
73
|
-
* Authlogic::Session::Params - Authentication via params, aka single access token.
|
|
74
|
-
* Authlogic::Session::Password - Authentication via a traditional username and password.
|
|
75
|
-
* Authlogic::Session::Persistence - Persisting sessions / finding sessions.
|
|
76
|
-
* Authlogic::Session::Session - Authentication via the session.
|
|
77
|
-
* Authlogic::Session::Timeout - Automatically logging out after a certain period of inactivity.
|
|
78
|
-
* Authlogic::Session::UnauthorizedRecord - Handles authentication by passing an ActiveRecord object.
|
|
79
|
-
* Authlogic::Session::Validation - Validation / errors.
|
|
110
|
+
These modules are for the models that extend Authlogic::Session::Base.
|
|
111
|
+
|
|
112
|
+
* <b>Authlogic::Session::BruteForceProtection</b> - Disables accounts after a certain number of consecutive failed logins attempted.
|
|
113
|
+
* <b>Authlogic::Session::Callbacks</b> - Your tools to extend, change, or add onto Authlogic. Lets you hook in and do just about anything you want. Start here if you want to write a plugin or add-on for Authlogic
|
|
114
|
+
* <b>Authlogic::Session::Cookies</b> - Authentication via cookies.
|
|
115
|
+
* <b>Authlogic::Session::Existence</b> - Creating, saving, and destroying objects.
|
|
116
|
+
* <b>Authlogic::Session::HttpAuth</b> - Authentication via basic HTTP authentication.
|
|
117
|
+
* <b>Authlogic::Session::Id</b> - Allows sessions to be separated by an id, letting you have multiple sessions for a single user.
|
|
118
|
+
* <b>Authlogic::Session::MagicColumns</b> - Maintains "magic" database columns, similar to created_at and updated_at for ActiveRecord.
|
|
119
|
+
* <b>Authlogic::Session::MagicStates</b> - Automatically validates based on the records states: active?, approved?, and confirmed?. If those methods exist for the record.
|
|
120
|
+
* <b>Authlogic::Session::Params</b> - Authentication via params, aka single access token.
|
|
121
|
+
* <b>Authlogic::Session::Password</b> - Authentication via a traditional username and password.
|
|
122
|
+
* <b>Authlogic::Session::Persistence</b> - Persisting sessions / finding sessions.
|
|
123
|
+
* <b>Authlogic::Session::Session</b> - Authentication via the session, the controller session that is.
|
|
124
|
+
* <b>Authlogic::Session::Timeout</b> - Automatically logging out after a certain period of inactivity.
|
|
125
|
+
* <b>Authlogic::Session::UnauthorizedRecord</b> - Handles authentication by passing an ActiveRecord object directly.
|
|
126
|
+
* <b>Authlogic::Session::Validation</b> - Validation / errors.
|
|
80
127
|
|
|
81
128
|
=== Miscellaneous modules
|
|
82
129
|
|
|
83
|
-
Miscellaneous modules that
|
|
130
|
+
Miscellaneous modules that shared across the authentication process and are more "utility" modules and classes.
|
|
84
131
|
|
|
85
|
-
* Authlogic::AuthenticatesMany - Responsible for allowing you to scope sessions to a parent record. Similar to a has_many and belongs_to relationship. This lets you do the same thing with sessions.
|
|
86
|
-
* Authlogic::CryptoProviders - Contains various encryption algorithms that Authlogic uses, allowing you to choose your encryption method.
|
|
87
|
-
* Authlogic::I18n - Acts JUST LIKE the rails I18n library, and provides internationalization to Authlogic.
|
|
88
|
-
* Authlogic::
|
|
89
|
-
* Authlogic::
|
|
132
|
+
* <b>Authlogic::AuthenticatesMany</b> - Responsible for allowing you to scope sessions to a parent record. Similar to a has_many and belongs_to relationship. This lets you do the same thing with sessions.
|
|
133
|
+
* <b>Authlogic::CryptoProviders</b> - Contains various encryption algorithms that Authlogic uses, allowing you to choose your encryption method.
|
|
134
|
+
* <b>Authlogic::I18n</b> - Acts JUST LIKE the rails I18n library, and provides internationalization to Authlogic.
|
|
135
|
+
* <b>Authlogic::Random</b> - A simple class to generate random tokens.
|
|
136
|
+
* <b>Authlogic::Regex</b> - Contains regular expressions used in Authlogic. Such as those to validate the format of the log or email.
|
|
137
|
+
* <b>Authlogic::TestCase</b> - Various helper methods for testing frameworks to help you test your code.
|
|
138
|
+
* <b>Authlogic::Version</b> - A handy class for determine the version of Authlogic in a number of ways.
|
|
90
139
|
|
|
91
|
-
== Quick example
|
|
140
|
+
== Quick Rails example
|
|
92
141
|
|
|
93
142
|
What if creating sessions worked like an ORM library on the surface...
|
|
94
143
|
|
|
@@ -146,123 +195,51 @@ Or how about persisting the session...
|
|
|
146
195
|
end
|
|
147
196
|
end
|
|
148
197
|
|
|
149
|
-
== Install
|
|
150
|
-
|
|
151
|
-
=== 1. Install the gem
|
|
198
|
+
== Install & Use
|
|
152
199
|
|
|
153
200
|
Install the gem / plugin (recommended)
|
|
154
201
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Now add the gem dependency in your config:
|
|
158
|
-
|
|
159
|
-
# config/environment.rb
|
|
160
|
-
config.gem "authlogic"
|
|
161
|
-
|
|
162
|
-
Or you install this as a plugin (for older versions of rails)
|
|
202
|
+
From rubyforge:
|
|
163
203
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
=== 2. Create your session
|
|
167
|
-
|
|
168
|
-
Lets assume you are setting up a session for your User model.
|
|
169
|
-
|
|
170
|
-
Create your user_session.rb file:
|
|
171
|
-
|
|
172
|
-
$ script/generate session user_session
|
|
173
|
-
|
|
174
|
-
This will create a file that looks similar to:
|
|
175
|
-
|
|
176
|
-
# app/models/user_session.rb
|
|
177
|
-
class UserSession < Authlogic::Session::Base
|
|
178
|
-
# configuration here, see sub modules of Authlogic::Session
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
=== 3. Ensure proper database fields
|
|
182
|
-
|
|
183
|
-
The user model should have the following columns. The names of these columns can be changed with configuration. Better yet, Authlogic tries to guess these names by checking for the existence of common names. See the sub modules of Authlogic::Session for more details, but chances are you won't have to specify any configuration for your field names, even if they aren't the same names as below.
|
|
184
|
-
|
|
185
|
-
t.string :login, :null => false # optional, you can use email instead, or both
|
|
186
|
-
t.string :crypted_password, :null => false
|
|
187
|
-
t.string :password_salt, :null => false # optional, but highly recommended
|
|
188
|
-
t.string :persistence_token, :null => false
|
|
189
|
-
t.string :single_access_token, :null => false # optional, see Authlogic::Session::Params
|
|
190
|
-
t.string :perishable_token, :null => false # optional, see Authlogic::Session::Perishability
|
|
191
|
-
t.integer :login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
|
192
|
-
t.integer :failed_login_count, :null => false, :default => 0 # optional, see Authlogic::Session::MagicColumns
|
|
193
|
-
t.datetime :last_request_at # optional, see Authlogic::Session::MagicColumns
|
|
194
|
-
t.datetime :current_login_at # optional, see Authlogic::Session::MagicColumns
|
|
195
|
-
t.datetime :last_login_at # optional, see Authlogic::Session::MagicColumns
|
|
196
|
-
t.string :current_login_ip # optional, see Authlogic::Session::MagicColumns
|
|
197
|
-
t.string :last_login_ip # optional, see Authlogic::Session::MagicColumns
|
|
198
|
-
|
|
199
|
-
=== 4. Set up your model
|
|
200
|
-
|
|
201
|
-
Make sure you have a model that you will be authenticating with. Since we are using the User model it should look something like:
|
|
202
|
-
|
|
203
|
-
class User < ActiveRecord::Base
|
|
204
|
-
acts_as_authentic do |c|
|
|
205
|
-
c.my_config_option = my_value # for available options see documentation in: Authlogic::ActsAsAuthentic
|
|
206
|
-
end # block optional
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
You are all set.
|
|
210
|
-
|
|
211
|
-
=== 5. Next Steps
|
|
212
|
-
|
|
213
|
-
Here are some common next steps. They might or might not apply to you. For a complete list of everything Authlogic can do please read the documentation or see the sub module list above.
|
|
214
|
-
|
|
215
|
-
1. Want to use another encryption algorithm, such as BCrypt? See Authlogic::ActsAsAuthentic::Password::Config
|
|
216
|
-
2. Migrating from restful_authentication? See Authlogic::ActsAsAuthentic::RestfulAuthentication::Config
|
|
217
|
-
3. Want to timeout sessions after a period if inactivity? See Authlogic::Session::Timeout
|
|
218
|
-
4. Need to scope your sessions to an account or parent model? See Authlogic::AuthenticatesMany
|
|
219
|
-
5. Need multiple session types in your app? Check out Authlogic::Session::Id
|
|
220
|
-
6. Need to reset passwords or activate accounts? Use the perishable token. See Authlogic::ActsAsAuthentic::PerishableToken
|
|
221
|
-
7. Need to give API access or access to a private feed? Use basic HTTP auth or authentication by params. See Authlogic::Session::HttpAuth or Authlogic::Session::Params
|
|
222
|
-
8. Need to internationalize your app? See Authlogic::I18n
|
|
223
|
-
9. Need help testing? See the Authlogic::Testing
|
|
224
|
-
|
|
225
|
-
== Interested in how it works?
|
|
226
|
-
|
|
227
|
-
Interested in how all of this all works? Basically a before filter is automatically set in your controller which lets Authlogic know about the current controller object. This "activates" Authlogic and allows Authlogic to set sessions, cookies, login via basic http auth, etc. If you are using your framework in a multiple thread environment, don't worry. I kept that in mind and made this thread safe.
|
|
228
|
-
|
|
229
|
-
From there it is pretty simple. When you try to create a new session the record is authenticated and then all of the session / cookie magic is done for you. The sky is the limit.
|
|
230
|
-
|
|
231
|
-
== What's wrong with the current solutions?
|
|
232
|
-
|
|
233
|
-
You probably don't care, but I think releasing the millionth ruby authentication solution requires a little explanation.
|
|
204
|
+
$ sudo gem install authlogic
|
|
234
205
|
|
|
235
|
-
|
|
206
|
+
Or from github:
|
|
236
207
|
|
|
237
|
-
|
|
208
|
+
$ sudo gem install binarylogic-authlogic
|
|
238
209
|
|
|
239
|
-
|
|
210
|
+
Now just add the gem dependency in your projects configuration.
|
|
240
211
|
|
|
241
|
-
|
|
212
|
+
Or you can install this as a plugin:
|
|
242
213
|
|
|
243
|
-
|
|
214
|
+
script/plugin install git://github.com/binarylogic/authlogic.git
|
|
244
215
|
|
|
245
|
-
|
|
216
|
+
== Detailed Setup Tutorial
|
|
246
217
|
|
|
247
|
-
|
|
218
|
+
See the {authlogic example}[http://github.com/binarylogic/authlogic_example/tree/master] for a detailed setup tutorial. I did this because not only do you have a tutorial to go by, but you have an example app that uses the same tutorial, so you can play around with with the code. If you have problems you can compare the code to see what you are doing differently.
|
|
248
219
|
|
|
249
|
-
|
|
220
|
+
== Testing
|
|
250
221
|
|
|
251
|
-
|
|
222
|
+
I think one of the best aspects of Authlogic is testing. For one, it cuts out <b>a lot</b> of redundant tests in your applications because Authlogic is already thoroughly tested for you. It doesn't include a bunch of tests into your application, because it comes tested, just like any other library.
|
|
252
223
|
|
|
253
|
-
|
|
224
|
+
For example, think about ActiveRecord. You don't test the internals of ActiveRecord, because the creators of ActiveRecord have already tested the internals for you. It wouldn't make sense for ActiveRecord to copy it's hundreds of tests into your applications. The same concept applies to Authlogic. You only need to test code you write that is specific to your application, just like everything else in your application.
|
|
254
225
|
|
|
255
|
-
|
|
226
|
+
That being said, testing your code that uses Authlogic is easy. Since everyone uses different testing suites, I created a helpful module called Authlogic::TestCase, which is basically a set of tools for testing code using Authlogic. I explain testing Authlogic thoroughly in the {Authlogic::TestCase section of the documentation}[http://rdoc.info/rdoc/binarylogic/authlogic/blob/f2f6988d3b97e11770b00b72a7a9733df69ffa5b/Authlogic/TestCase.html]. It should answer any questions you have in regards to testing Authlogic.
|
|
256
227
|
|
|
257
|
-
|
|
228
|
+
== Tell me quickly how Authlogic works
|
|
258
229
|
|
|
259
|
-
|
|
230
|
+
Interested in how all of this all works? Think about an ActiveRecord model. A database connection must be established before you can use it. In the case of Authlogic, a controller connection must be established before you can use it. It uses that controller connection to modify cookies, the current session, login with HTTP basic, etc. It connects to the controller through a before filter that is automatically set in your controller which lets Authlogic know about the current controller object. Then Authlogic leverages that to do everything, it's a pretty simple design. Nothing crazy going on, Authlogic is just leveraging the tools your framework provides in the controller object.
|
|
260
231
|
|
|
261
|
-
|
|
232
|
+
== What sets Authlogic apart and why I created it
|
|
262
233
|
|
|
263
|
-
|
|
234
|
+
What inspired me to create Authlogic was the messiness of the current authentication solutions. Put simply, they just didn't feel right, because the logic was not organized properly. As you may know, a common misconception with the MVC design pattern is that the model "M" is only for data access logic, which is wrong. A model is a place for domain logic. This is why the RESTful design pattern and the current authentication solutions don't play nice. Authlogic solves this by placing the session maintenance logic into its own domain (aka "model"). Moving session maintenance into its own domain has its benefits:
|
|
264
235
|
|
|
265
|
-
|
|
236
|
+
1. <b>It's cleaner.</b> There are no generators in Authlogic. Authlogic provides a class that you can use, it's plain and simple ruby. More importantly, the code in your app is code you write, written the way you want, nice and clean. It's code that should be in your app and is specific to your app, not a redundant authentication pattern.
|
|
237
|
+
2. <b>Easier to stay up-to-date.</b> To make my point, take a look at the commits to any other authentication solution, then look at the {commits for authlogic}[http://github.com/binarylogic/authlogic/commits/master]. How many commits could you easily start using if you already had an app using that solution? With an alternate solution, very few, if any. All of those cool new features and bug fixes are going to have be manually added or wait for your next application. Which is the main reason a generator is not suitable as an authentication solution. With Authlogic you can start using the latest code with a simple update of a gem. No generators, no mess.
|
|
238
|
+
3. <b>It ties everything together on the domain level.</b> Take a new user registration for example, no reason to manually log the user in, authlogic handles this for you via callbacks. The same applies to a user changing their password. Authlogic handles maintaining the session for you.
|
|
239
|
+
4. <b>No redundant tests.</b> Because Authlogic doesn't use generators, #1 also applies to tests. Authlogic is *thoroughly* tested for you. You don't go and test the internals of ActiveRecord in each of your apps do you? So why do the same for Authlogic? Your application tests should be for application specific code. Get rid of the noise and make your tests focused and concise, no reason to copy tests from app to app.
|
|
240
|
+
5. <b>Framework agnostic</b>. Authlogic can be used in *any* ruby framework you want: Rails, Merb, Sinatra, Mack, your own framework, whatever. It's not tied down to Rails. It does this by abstracting itself from these framework's controllers by using a controller adapter. Thanks to {Rack}[http://rack.rubyforge.org/], there is a defined standard for controller structure, and that's what Authlogic's abstract adapter follows. So if your controller follows the rack standards, you don't need to do anything. Any place it deviates from this is solved by a simple adapter for your framework that closes these gaps. For an example, checkout the Authlogic::ControllerAdapters::MerbAdapter.
|
|
241
|
+
5. <b>You are not restricted to a single session.</b> Think about Apple's me.com, where they need you to authenticate a second time before changing your billing information. Why not just create a second session for this? It works just like your initial session. Then your billing controller can require an "ultra secure" session.
|
|
242
|
+
6. <b>Easily extendable.</b> One of the distinct advantages of using a library is the ability to use its API, assuming it has one. Authlogic has an *excellent* public API, meaning it can easily be extended and grow beyond the core library. Checkout the "add ons" list above to see what I mean.
|
|
266
243
|
|
|
267
244
|
|
|
268
|
-
Copyright (c)
|
|
245
|
+
Copyright (c) 2009 {Ben Johnson of Binary Logic}[http://www.binarylogic.com], released under the MIT license
|
data/Rakefile
CHANGED
|
@@ -1,21 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'rake'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
require
|
|
5
|
-
|
|
4
|
+
begin
|
|
5
|
+
require 'jeweler'
|
|
6
|
+
Jeweler::Tasks.new do |gem|
|
|
7
|
+
gem.name = "authlogic"
|
|
8
|
+
gem.summary = "A clean, simple, and unobtrusive ruby authentication solution."
|
|
9
|
+
gem.email = "bjohnson@binarylogic.com"
|
|
10
|
+
gem.homepage = "http://github.com/binarylogic/authlogic"
|
|
11
|
+
gem.authors = ["Ben Johnson of Binary Logic"]
|
|
12
|
+
gem.rubyforge_project = "authlogic"
|
|
13
|
+
gem.add_dependency "activesupport"
|
|
14
|
+
end
|
|
15
|
+
Jeweler::RubyforgeTasks.new
|
|
16
|
+
rescue LoadError
|
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
|
18
|
+
end
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
require 'rake/testtask'
|
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
|
22
|
+
test.libs << 'test'
|
|
23
|
+
test.pattern = 'test/**/*_test.rb'
|
|
24
|
+
test.verbose = true
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
begin
|
|
28
|
+
require 'rcov/rcovtask'
|
|
29
|
+
Rcov::RcovTask.new do |test|
|
|
30
|
+
test.libs << 'test'
|
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
|
32
|
+
test.verbose = true
|
|
33
|
+
end
|
|
34
|
+
rescue LoadError
|
|
35
|
+
task :rcov do
|
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
task :test => :check_dependencies
|
|
41
|
+
|
|
42
|
+
task :default => :test
|
data/VERSION.yml
ADDED