authlogic 3.4.6 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +33 -0
  4. data/.rubocop_todo.yml +427 -0
  5. data/.travis.yml +24 -3
  6. data/CHANGELOG.md +9 -2
  7. data/CONTRIBUTING.md +40 -1
  8. data/Gemfile +1 -1
  9. data/README.md +295 -0
  10. data/Rakefile +10 -2
  11. data/authlogic.gemspec +6 -5
  12. data/lib/authlogic.rb +2 -2
  13. data/lib/authlogic/acts_as_authentic/base.rb +2 -2
  14. data/lib/authlogic/acts_as_authentic/email.rb +59 -14
  15. data/lib/authlogic/acts_as_authentic/logged_in_status.rb +4 -3
  16. data/lib/authlogic/acts_as_authentic/login.rb +62 -12
  17. data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
  18. data/lib/authlogic/acts_as_authentic/password.rb +107 -53
  19. data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -9
  20. data/lib/authlogic/acts_as_authentic/restful_authentication.rb +2 -0
  21. data/lib/authlogic/acts_as_authentic/session_maintenance.rb +48 -35
  22. data/lib/authlogic/acts_as_authentic/single_access_token.rb +19 -15
  23. data/lib/authlogic/acts_as_authentic/validations_scope.rb +2 -2
  24. data/lib/authlogic/authenticates_many/association.rb +6 -5
  25. data/lib/authlogic/authenticates_many/base.rb +22 -12
  26. data/lib/authlogic/config.rb +2 -1
  27. data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -1
  28. data/lib/authlogic/controller_adapters/rack_adapter.rb +3 -4
  29. data/lib/authlogic/controller_adapters/rails_adapter.rb +26 -14
  30. data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
  31. data/lib/authlogic/crypto_providers/aes256.rb +16 -12
  32. data/lib/authlogic/crypto_providers/bcrypt.rb +10 -4
  33. data/lib/authlogic/crypto_providers/md5.rb +7 -7
  34. data/lib/authlogic/crypto_providers/scrypt.rb +10 -2
  35. data/lib/authlogic/crypto_providers/sha1.rb +3 -3
  36. data/lib/authlogic/crypto_providers/sha256.rb +3 -3
  37. data/lib/authlogic/crypto_providers/sha512.rb +4 -4
  38. data/lib/authlogic/crypto_providers/wordpress.rb +13 -13
  39. data/lib/authlogic/i18n.rb +22 -16
  40. data/lib/authlogic/i18n/translator.rb +1 -1
  41. data/lib/authlogic/random.rb +13 -12
  42. data/lib/authlogic/regex.rb +3 -3
  43. data/lib/authlogic/session/activation.rb +7 -6
  44. data/lib/authlogic/session/active_record_trickery.rb +1 -2
  45. data/lib/authlogic/session/base.rb +7 -6
  46. data/lib/authlogic/session/brute_force_protection.rb +58 -34
  47. data/lib/authlogic/session/callbacks.rb +16 -12
  48. data/lib/authlogic/session/cookies.rb +29 -14
  49. data/lib/authlogic/session/existence.rb +10 -10
  50. data/lib/authlogic/session/foundation.rb +11 -7
  51. data/lib/authlogic/session/http_auth.rb +6 -5
  52. data/lib/authlogic/session/id.rb +5 -4
  53. data/lib/authlogic/session/klass.rb +2 -1
  54. data/lib/authlogic/session/magic_columns.rb +21 -14
  55. data/lib/authlogic/session/magic_states.rb +25 -14
  56. data/lib/authlogic/session/params.rb +41 -26
  57. data/lib/authlogic/session/password.rb +62 -40
  58. data/lib/authlogic/session/perishable_token.rb +3 -2
  59. data/lib/authlogic/session/persistence.rb +3 -3
  60. data/lib/authlogic/session/priority_record.rb +5 -4
  61. data/lib/authlogic/session/scopes.rb +20 -9
  62. data/lib/authlogic/session/session.rb +9 -4
  63. data/lib/authlogic/session/timeout.rb +40 -23
  64. data/lib/authlogic/session/unauthorized_record.rb +6 -5
  65. data/lib/authlogic/session/validation.rb +18 -9
  66. data/lib/authlogic/test_case.rb +2 -2
  67. data/lib/authlogic/test_case/mock_controller.rb +9 -9
  68. data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -2
  69. data/lib/authlogic/test_case/mock_logger.rb +1 -1
  70. data/lib/authlogic/test_case/mock_request.rb +2 -1
  71. data/lib/authlogic/test_case/rails_request_adapter.rb +5 -5
  72. data/test/acts_as_authentic_test/email_test.rb +29 -17
  73. data/test/acts_as_authentic_test/logged_in_status_test.rb +9 -3
  74. data/test/acts_as_authentic_test/login_test.rb +47 -13
  75. data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
  76. data/test/acts_as_authentic_test/password_test.rb +31 -21
  77. data/test/acts_as_authentic_test/perishable_token_test.rb +15 -15
  78. data/test/acts_as_authentic_test/session_maintenance_test.rb +20 -13
  79. data/test/acts_as_authentic_test/single_access_test.rb +8 -8
  80. data/test/authenticates_many_test.rb +4 -4
  81. data/test/crypto_provider_test/aes256_test.rb +2 -2
  82. data/test/crypto_provider_test/scrypt_test.rb +1 -1
  83. data/test/crypto_provider_test/sha1_test.rb +3 -3
  84. data/test/crypto_provider_test/sha256_test.rb +1 -1
  85. data/test/crypto_provider_test/sha512_test.rb +2 -2
  86. data/test/gemfiles/Gemfile.rails-3.2.x +2 -2
  87. data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
  88. data/test/i18n_test.rb +5 -5
  89. data/test/libs/affiliate.rb +2 -2
  90. data/test/libs/company.rb +1 -1
  91. data/test/libs/employee.rb +2 -2
  92. data/test/libs/employee_session.rb +1 -1
  93. data/test/libs/ldaper.rb +1 -1
  94. data/test/libs/project.rb +1 -1
  95. data/test/random_test.rb +5 -4
  96. data/test/session_test/activation_test.rb +5 -5
  97. data/test/session_test/active_record_trickery_test.rb +7 -5
  98. data/test/session_test/cookies_test.rb +8 -6
  99. data/test/session_test/existence_test.rb +19 -13
  100. data/test/session_test/http_auth_test.rb +0 -3
  101. data/test/session_test/id_test.rb +2 -2
  102. data/test/session_test/klass_test.rb +1 -1
  103. data/test/session_test/magic_columns_test.rb +0 -3
  104. data/test/session_test/magic_states_test.rb +11 -11
  105. data/test/session_test/params_test.rb +10 -10
  106. data/test/session_test/password_test.rb +4 -5
  107. data/test/session_test/perishability_test.rb +3 -3
  108. data/test/session_test/scopes_test.rb +8 -8
  109. data/test/session_test/session_test.rb +5 -4
  110. data/test/session_test/timeout_test.rb +8 -8
  111. data/test/session_test/unauthorized_record_test.rb +2 -2
  112. data/test/session_test/validation_test.rb +3 -3
  113. data/test/test_helper.rb +9 -5
  114. metadata +54 -24
  115. data/README.rdoc +0 -232
@@ -1,232 +0,0 @@
1
- = Authlogic
2
-
3
- ** Authlogic supports both rails 3 and 4. For rails 2, see the rail2 branch
4
-
5
- {<img src="https://travis-ci.org/binarylogic/authlogic.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/binarylogic/authlogic]
6
-
7
- {<img src="https://codeclimate.com/github/binarylogic/authlogic.png" />}[https://codeclimate.com/github/binarylogic/authlogic]
8
-
9
- Authlogic is a clean, simple, and unobtrusive ruby authentication solution.
10
-
11
- A code example can replace a thousand words...
12
-
13
- 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:
14
-
15
- class UserSession < Authlogic::Session::Base
16
- # specify configuration here, such as:
17
- # logout_on_timeout true
18
- # ...many more options in the documentation
19
- end
20
-
21
- Log in with any of the following. Create a UserSessionsController and use it just like your other models:
22
-
23
- UserSession.create(:login => "bjohnson", :password => "my password", :remember_me => true)
24
- session = UserSession.new(:login => "bjohnson", :password => "my password", :remember_me => true); session.save
25
- UserSession.create(:openid_identifier => "identifier", :remember_me => true) # requires the authlogic-oid "add on" gem
26
- UserSession.create(my_user_object, true) # skip authentication and log the user in directly, the true means "remember me"
27
-
28
- 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.
29
-
30
- You can also log out / destroy the session:
31
-
32
- session.destroy
33
-
34
- After a session has been created, you can persist it across requests. Thus keeping the user logged in:
35
-
36
- session = UserSession.find
37
-
38
- To get all of the nice authentication functionality in your model just do this:
39
-
40
- class User < ActiveRecord::Base
41
- acts_as_authentic do |c|
42
- c.my_config_option = my_value
43
- end # the configuration block is optional
44
- end
45
-
46
- 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.
47
-
48
- You may specify how passwords are cryptographically hashed (or encrypted) by setting the Authlogic::CryptoProvider option:
49
-
50
- c.crypto_provider = Authlogic::CryptoProviders::BCrypt
51
-
52
- You may validate international email addresses by enabling the provided alternate regex:
53
-
54
- c.validates_format_of_email_field_options = {:with => Authlogic::Regex.email_nonascii}
55
-
56
- 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:
57
-
58
- User.create(params[:user])
59
-
60
- This also updates the session when the user changes his/her password.
61
-
62
- 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.
63
-
64
- == Upgrading to Authlogic 3.4.0
65
-
66
- In version 3.4.0, the default crypto_provider was changed from *Sha512* to *SCrypt*.
67
-
68
- If you never set a crypto_provider and are upgrading, your passwords will break unless you set the original:
69
-
70
- c.crypto_provider = Authlogic::CryptoProviders::Sha512
71
-
72
- And if you want to automatically upgrade from *Sha512* to *SCrypt* as users login:
73
-
74
- c.transition_from_crypto_providers = [Authlogic::CryptoProviders::Sha512]
75
- c.crypto_provider = Authlogic::CryptoProviders::SCrypt
76
-
77
- == Helpful links
78
-
79
- * <b>Documentation:</b> http://rdoc.info/projects/binarylogic/authlogic
80
- * <b>Repository:</b> http://github.com/binarylogic/authlogic/tree/master
81
- * <b>Railscasts Screencast:</b> http://railscasts.com/episodes/160-authlogic
82
- * <b>Example repository with tutorial in README:</b> http://github.com/binarylogic/authlogic_example/tree/master
83
- * <b>Tutorial: Reset passwords with Authlogic the RESTful way:</b> http://www.binarylogic.com/2008/11/16/tutorial-reset-passwords-with-authlogic
84
- * <b>Issues:</b> http://github.com/binarylogic/authlogic/issues
85
-
86
- == Authlogic "add ons"
87
-
88
- * <b>Authlogic OpenID addon:</b> http://github.com/binarylogic/authlogic_openid
89
- * <b>Authlogic LDAP addon:</b> http://github.com/binarylogic/authlogic_ldap
90
- * <b>Authlogic Facebook Connect:</b> http://github.com/kalasjocke/authlogic_facebook_connect
91
- * <b>Authlogic Facebook Connect (New JS API):</b> http://github.com/studybyte/authlogic_facebook_connect
92
- * <b>Authlogic Facebook Shim</b> http://github.com/james2m/authlogic_facebook_shim
93
- * <b>Authlogic OAuth (Twitter):</b> http://github.com/jrallison/authlogic_oauth
94
- * <b>Authlogic Oauth and OpenID:</b> http://github.com/viatropos/authlogic-connect
95
- * <b>Authlogic PAM:</b> http://github.com/nbudin/authlogic_pam
96
- * <b>Authlogic x509:</b> http://github.com/auth-scc/authlogic_x509
97
-
98
- 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.
99
-
100
- == Documentation explanation
101
-
102
- You can find anything you want about Authlogic in the {documentation}[http://rdoc.info/projects/binarylogic/authlogic], all that you need to do is understand the basic design behind it.
103
-
104
- That being said, there are 2 models involved during authentication. Your Authlogic model and your ActiveRecord model:
105
-
106
- 1. <b>Authlogic::Session</b>, your session models that extend Authlogic::Session::Base.
107
- 2. <b>Authlogic::ActsAsAuthentic</b>, which adds in functionality to your ActiveRecord model when you call acts_as_authentic.
108
-
109
- 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.
110
-
111
- 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://rdoc.info/projects/binarylogic/authlogic].
112
-
113
- == Example migration
114
-
115
- If you want to enable all the features of Authlogic, a migration to create a
116
- +User+ model, for example, might look like this:
117
-
118
- class CreateUser < ActiveRecord::Migration
119
- def change
120
- create_table :users do |t|
121
- # Authlogic::ActsAsAuthentic::Email
122
- t.string :email
123
-
124
- # Authlogic::ActsAsAuthentic::Password
125
- t.string :crypted_password
126
- t.string :password_salt
127
-
128
- # Authlogic::ActsAsAuthentic::PersistenceToken
129
- t.string :persistence_token
130
-
131
- # Authlogic::ActsAsAuthentic::SingleAccessToken
132
- t.string :single_access_token
133
-
134
- # Authlogic::ActsAsAuthentic::PerishableToken
135
- t.string :perishable_token
136
-
137
- # Authlogic::Session::MagicColumns
138
- t.integer :login_count, default: 0, null: false
139
- t.integer :failed_login_count, default: 0, null: false
140
- t.datetime :last_request_at
141
- t.datetime :current_login_at
142
- t.datetime :last_login_at
143
- t.string :current_login_ip
144
- t.string :last_login_ip
145
-
146
- # Authlogic::Session::MagicStates
147
- t.boolean :active, default: false
148
- t.boolean :approved, default: false
149
- t.boolean :confirmed, default: false
150
-
151
- t.timestamps
152
- end
153
- end
154
- end
155
-
156
- == Quick Rails example
157
-
158
- What if creating sessions worked like an ORM library on the surface...
159
-
160
- UserSession.create(params[:user_session])
161
-
162
- What if your user sessions controller could look just like your other controllers...
163
-
164
- class UserSessionsController < ApplicationController
165
- def new
166
- @user_session = UserSession.new
167
- end
168
-
169
- def create
170
- @user_session = UserSession.new(params[:user_session])
171
- if @user_session.save
172
- redirect_to account_url
173
- else
174
- render :action => :new
175
- end
176
- end
177
-
178
- def destroy
179
- current_user_session.destroy
180
- redirect_to new_user_session_url
181
- end
182
- end
183
-
184
- As you can see, this fits nicely into the RESTful development pattern. What about the view...
185
-
186
- <%= form_for @user_session do |f| %>
187
- <% if @user_session.errors.any? %>
188
- <div id="error_explanation">
189
- <h2><%= pluralize(@user_session.errors.count, "error") %> prohibited:</h2>
190
- <ul>
191
- <% @user_session.errors.full_messages.each do |msg| %>
192
- <li><%= msg %></li>
193
- <% end %>
194
- </ul>
195
- </div>
196
- <% end %>
197
- <%= f.label :login %><br />
198
- <%= f.text_field :login %><br />
199
- <br />
200
- <%= f.label :password %><br />
201
- <%= f.password_field :password %><br />
202
- <br />
203
- <%= f.submit "Login" %>
204
- <% end %>
205
-
206
- Or how about persisting the session...
207
-
208
- class ApplicationController
209
- helper_method :current_user_session, :current_user
210
-
211
- private
212
- def current_user_session
213
- return @current_user_session if defined?(@current_user_session)
214
- @current_user_session = UserSession.find
215
- end
216
-
217
- def current_user
218
- return @current_user if defined?(@current_user)
219
- @current_user = current_user_session && current_user_session.user
220
- end
221
- end
222
-
223
- == Testing
224
-
225
- See Authlogic::TestCase
226
-
227
- == Tell me quickly how Authlogic works
228
-
229
- 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.
230
-
231
-
232
- Copyright (c) 2012 {Ben Johnson of Binary Logic}[http://www.binarylogic.com], released under the MIT license