authlogic 3.4.6 → 3.5.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 +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +33 -0
- data/.rubocop_todo.yml +427 -0
- data/.travis.yml +24 -3
- data/CHANGELOG.md +9 -2
- data/CONTRIBUTING.md +40 -1
- data/Gemfile +1 -1
- data/README.md +295 -0
- data/Rakefile +10 -2
- data/authlogic.gemspec +6 -5
- data/lib/authlogic.rb +2 -2
- data/lib/authlogic/acts_as_authentic/base.rb +2 -2
- data/lib/authlogic/acts_as_authentic/email.rb +59 -14
- data/lib/authlogic/acts_as_authentic/logged_in_status.rb +4 -3
- data/lib/authlogic/acts_as_authentic/login.rb +62 -12
- data/lib/authlogic/acts_as_authentic/magic_columns.rb +17 -6
- data/lib/authlogic/acts_as_authentic/password.rb +107 -53
- data/lib/authlogic/acts_as_authentic/persistence_token.rb +10 -9
- data/lib/authlogic/acts_as_authentic/restful_authentication.rb +2 -0
- data/lib/authlogic/acts_as_authentic/session_maintenance.rb +48 -35
- data/lib/authlogic/acts_as_authentic/single_access_token.rb +19 -15
- data/lib/authlogic/acts_as_authentic/validations_scope.rb +2 -2
- data/lib/authlogic/authenticates_many/association.rb +6 -5
- data/lib/authlogic/authenticates_many/base.rb +22 -12
- data/lib/authlogic/config.rb +2 -1
- data/lib/authlogic/controller_adapters/abstract_adapter.rb +2 -1
- data/lib/authlogic/controller_adapters/rack_adapter.rb +3 -4
- data/lib/authlogic/controller_adapters/rails_adapter.rb +26 -14
- data/lib/authlogic/controller_adapters/sinatra_adapter.rb +1 -1
- data/lib/authlogic/crypto_providers/aes256.rb +16 -12
- data/lib/authlogic/crypto_providers/bcrypt.rb +10 -4
- data/lib/authlogic/crypto_providers/md5.rb +7 -7
- data/lib/authlogic/crypto_providers/scrypt.rb +10 -2
- data/lib/authlogic/crypto_providers/sha1.rb +3 -3
- data/lib/authlogic/crypto_providers/sha256.rb +3 -3
- data/lib/authlogic/crypto_providers/sha512.rb +4 -4
- data/lib/authlogic/crypto_providers/wordpress.rb +13 -13
- data/lib/authlogic/i18n.rb +22 -16
- data/lib/authlogic/i18n/translator.rb +1 -1
- data/lib/authlogic/random.rb +13 -12
- data/lib/authlogic/regex.rb +3 -3
- data/lib/authlogic/session/activation.rb +7 -6
- data/lib/authlogic/session/active_record_trickery.rb +1 -2
- data/lib/authlogic/session/base.rb +7 -6
- data/lib/authlogic/session/brute_force_protection.rb +58 -34
- data/lib/authlogic/session/callbacks.rb +16 -12
- data/lib/authlogic/session/cookies.rb +29 -14
- data/lib/authlogic/session/existence.rb +10 -10
- data/lib/authlogic/session/foundation.rb +11 -7
- data/lib/authlogic/session/http_auth.rb +6 -5
- data/lib/authlogic/session/id.rb +5 -4
- data/lib/authlogic/session/klass.rb +2 -1
- data/lib/authlogic/session/magic_columns.rb +21 -14
- data/lib/authlogic/session/magic_states.rb +25 -14
- data/lib/authlogic/session/params.rb +41 -26
- data/lib/authlogic/session/password.rb +62 -40
- data/lib/authlogic/session/perishable_token.rb +3 -2
- data/lib/authlogic/session/persistence.rb +3 -3
- data/lib/authlogic/session/priority_record.rb +5 -4
- data/lib/authlogic/session/scopes.rb +20 -9
- data/lib/authlogic/session/session.rb +9 -4
- data/lib/authlogic/session/timeout.rb +40 -23
- data/lib/authlogic/session/unauthorized_record.rb +6 -5
- data/lib/authlogic/session/validation.rb +18 -9
- data/lib/authlogic/test_case.rb +2 -2
- data/lib/authlogic/test_case/mock_controller.rb +9 -9
- data/lib/authlogic/test_case/mock_cookie_jar.rb +2 -2
- data/lib/authlogic/test_case/mock_logger.rb +1 -1
- data/lib/authlogic/test_case/mock_request.rb +2 -1
- data/lib/authlogic/test_case/rails_request_adapter.rb +5 -5
- data/test/acts_as_authentic_test/email_test.rb +29 -17
- data/test/acts_as_authentic_test/logged_in_status_test.rb +9 -3
- data/test/acts_as_authentic_test/login_test.rb +47 -13
- data/test/acts_as_authentic_test/magic_columns_test.rb +4 -4
- data/test/acts_as_authentic_test/password_test.rb +31 -21
- data/test/acts_as_authentic_test/perishable_token_test.rb +15 -15
- data/test/acts_as_authentic_test/session_maintenance_test.rb +20 -13
- data/test/acts_as_authentic_test/single_access_test.rb +8 -8
- data/test/authenticates_many_test.rb +4 -4
- data/test/crypto_provider_test/aes256_test.rb +2 -2
- data/test/crypto_provider_test/scrypt_test.rb +1 -1
- data/test/crypto_provider_test/sha1_test.rb +3 -3
- data/test/crypto_provider_test/sha256_test.rb +1 -1
- data/test/crypto_provider_test/sha512_test.rb +2 -2
- data/test/gemfiles/Gemfile.rails-3.2.x +2 -2
- data/test/gemfiles/Gemfile.rails-5.0.x +6 -0
- data/test/i18n_test.rb +5 -5
- data/test/libs/affiliate.rb +2 -2
- data/test/libs/company.rb +1 -1
- data/test/libs/employee.rb +2 -2
- data/test/libs/employee_session.rb +1 -1
- data/test/libs/ldaper.rb +1 -1
- data/test/libs/project.rb +1 -1
- data/test/random_test.rb +5 -4
- data/test/session_test/activation_test.rb +5 -5
- data/test/session_test/active_record_trickery_test.rb +7 -5
- data/test/session_test/cookies_test.rb +8 -6
- data/test/session_test/existence_test.rb +19 -13
- data/test/session_test/http_auth_test.rb +0 -3
- data/test/session_test/id_test.rb +2 -2
- data/test/session_test/klass_test.rb +1 -1
- data/test/session_test/magic_columns_test.rb +0 -3
- data/test/session_test/magic_states_test.rb +11 -11
- data/test/session_test/params_test.rb +10 -10
- data/test/session_test/password_test.rb +4 -5
- data/test/session_test/perishability_test.rb +3 -3
- data/test/session_test/scopes_test.rb +8 -8
- data/test/session_test/session_test.rb +5 -4
- data/test/session_test/timeout_test.rb +8 -8
- data/test/session_test/unauthorized_record_test.rb +2 -2
- data/test/session_test/validation_test.rb +3 -3
- data/test/test_helper.rb +9 -5
- metadata +54 -24
- data/README.rdoc +0 -232
@@ -7,7 +7,7 @@ module Authlogic
|
|
7
7
|
super("Your session is invalid and has the following errors: #{session.errors.full_messages.to_sentence}")
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def self.included(klass)
|
12
12
|
klass.class_eval do
|
13
13
|
extend ClassMethods
|
@@ -15,9 +15,9 @@ module Authlogic
|
|
15
15
|
attr_accessor :new_session, :record
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
module ClassMethods
|
20
|
-
# A
|
20
|
+
# A convenience method. The same as:
|
21
21
|
#
|
22
22
|
# session = UserSession.new(*args)
|
23
23
|
# session.save
|
@@ -30,7 +30,7 @@ module Authlogic
|
|
30
30
|
session.save(&block)
|
31
31
|
session
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
# Same as create but calls create!, which raises an exception when validation fails.
|
35
35
|
def create!(*args)
|
36
36
|
session = new(*args)
|
@@ -38,9 +38,9 @@ module Authlogic
|
|
38
38
|
session
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
module InstanceMethods
|
43
|
-
# Clears all errors and the associated record, you should call this terminate a session, thus
|
43
|
+
# Clears all errors and the associated record, you should call this terminate a session, thus requiring
|
44
44
|
# the user to authenticate again if it is needed.
|
45
45
|
def destroy
|
46
46
|
before_destroy
|
@@ -50,16 +50,16 @@ module Authlogic
|
|
50
50
|
after_destroy
|
51
51
|
true
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
# Returns true if the session is new, meaning no action has been taken on it and a successful save
|
55
55
|
# has not taken place.
|
56
56
|
def new_session?
|
57
57
|
new_session != false
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
# After you have specified all of the details for your session you can try to save it. This will
|
61
61
|
# run validation checks and find the associated record, if all validation passes. If validation
|
62
|
-
# does not pass, the save will fail and the
|
62
|
+
# does not pass, the save will fail and the errors will be stored in the errors object.
|
63
63
|
def save(&block)
|
64
64
|
result = nil
|
65
65
|
if valid?
|
@@ -90,4 +90,4 @@ module Authlogic
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
end
|
93
|
-
end
|
93
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module Session
|
3
|
-
# Sort of like an interface, it sets the foundation for the class, such as the
|
4
|
-
# other modules to overwrite methods and call super
|
5
|
-
# throughout Authlogic.
|
3
|
+
# Sort of like an interface, it sets the foundation for the class, such as the
|
4
|
+
# required methods. This also allows other modules to overwrite methods and call super
|
5
|
+
# on them. It's also a place to put "utility" methods used throughout Authlogic.
|
6
6
|
module Foundation
|
7
7
|
def self.included(klass)
|
8
8
|
klass.class_eval do
|
@@ -16,12 +16,14 @@ module Authlogic
|
|
16
16
|
self.credentials = args
|
17
17
|
end
|
18
18
|
|
19
|
-
# The credentials you passed to create your session. See credentials= for more
|
19
|
+
# The credentials you passed to create your session. See credentials= for more
|
20
|
+
# info.
|
20
21
|
def credentials
|
21
22
|
[]
|
22
23
|
end
|
23
24
|
|
24
|
-
# Set your credentials before you save your session. You can pass a hash of
|
25
|
+
# Set your credentials before you save your session. You can pass a hash of
|
26
|
+
# credentials:
|
25
27
|
#
|
26
28
|
# session.credentials = {:login => "my login", :password => "my password", :remember_me => true}
|
27
29
|
#
|
@@ -29,8 +31,9 @@ module Authlogic
|
|
29
31
|
#
|
30
32
|
# session.credentials = [my_user_object, true]
|
31
33
|
#
|
32
|
-
# and if you need to set an id, just pass it last. This value need be the last
|
33
|
-
#
|
34
|
+
# and if you need to set an id, just pass it last. This value need be the last
|
35
|
+
# item in the array you pass, since the id is something that you control yourself,
|
36
|
+
# it should never be set from a hash or a form. Examples:
|
34
37
|
#
|
35
38
|
# session.credentials = [{:login => "my login", :password => "my password", :remember_me => true}, :my_id]
|
36
39
|
# session.credentials = [my_user_object, true, :my_id]
|
@@ -42,6 +45,7 @@ module Authlogic
|
|
42
45
|
end
|
43
46
|
|
44
47
|
private
|
48
|
+
|
45
49
|
def build_key(last_part)
|
46
50
|
last_part
|
47
51
|
end
|
@@ -14,7 +14,7 @@ module Authlogic
|
|
14
14
|
persist :persist_by_http_auth, :if => :persist_by_http_auth?
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Configuration for the HTTP basic auth feature of Authlogic.
|
19
19
|
module Config
|
20
20
|
# Do you want to allow your users to log in via HTTP basic auth?
|
@@ -64,14 +64,15 @@ module Authlogic
|
|
64
64
|
end
|
65
65
|
alias_method :http_basic_auth_realm=, :http_basic_auth_realm
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# Instance methods for the HTTP basic auth feature of authlogic.
|
69
69
|
module InstanceMethods
|
70
70
|
private
|
71
|
+
|
71
72
|
def persist_by_http_auth?
|
72
73
|
allow_http_basic_auth? && login_field && password_field
|
73
74
|
end
|
74
|
-
|
75
|
+
|
75
76
|
def persist_by_http_auth
|
76
77
|
login_proc = Proc.new do |login, password|
|
77
78
|
if !login.blank? && !password.blank?
|
@@ -86,10 +87,10 @@ module Authlogic
|
|
86
87
|
else
|
87
88
|
controller.authenticate_with_http_basic(&login_proc)
|
88
89
|
end
|
89
|
-
|
90
|
+
|
90
91
|
false
|
91
92
|
end
|
92
|
-
|
93
|
+
|
93
94
|
def allow_http_basic_auth?
|
94
95
|
self.class.allow_http_basic_auth == true
|
95
96
|
end
|
data/lib/authlogic/session/id.rb
CHANGED
@@ -7,14 +7,14 @@ module Authlogic
|
|
7
7
|
attr_writer :id
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
# Setting the id if it is passed in the credentials.
|
12
12
|
def credentials=(value)
|
13
13
|
super
|
14
14
|
values = value.is_a?(Array) ? value : [value]
|
15
15
|
self.id = values.last if values.last.is_a?(Symbol)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Allows you to set a unique identifier for your session, so that you can have more than 1 session at a time.
|
19
19
|
# A good example when this might be needed is when you want to have a normal user session and a "secure" user session.
|
20
20
|
# The secure user session would be created only when they want to modify their billing information, or other sensitive
|
@@ -30,12 +30,13 @@ module Authlogic
|
|
30
30
|
def id
|
31
31
|
@id
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
private
|
35
|
+
|
35
36
|
# Used for things like cookie_key, session_key, etc.
|
36
37
|
def build_key(last_part)
|
37
38
|
[id, super].compact.join("_")
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
41
|
-
end
|
42
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module Session
|
3
|
-
# Just like ActiveRecord has "magic" columns, such as: created_at and updated_at.
|
3
|
+
# Just like ActiveRecord has "magic" columns, such as: created_at and updated_at.
|
4
|
+
# Authlogic has its own "magic" columns too:
|
4
5
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
6
|
+
# * login_count - Increased every time an explicit login is made. This will *NOT*
|
7
|
+
# increase if logging in by a session, cookie, or basic http auth
|
8
|
+
# * failed_login_count - This increases for each consecutive failed login. See
|
9
|
+
# Authlogic::Session::BruteForceProtection and the consecutive_failed_logins_limit
|
10
|
+
# config option for more details.
|
11
|
+
# * last_request_at - Updates every time the user logs in, either by explicitly
|
12
|
+
# logging in, or logging in by cookie, session, or http auth
|
13
|
+
# * current_login_at - Updates with the current time when an explicit login is made.
|
14
|
+
# * last_login_at - Updates with the value of current_login_at before it is reset.
|
15
|
+
# * current_login_ip - Updates with the request ip when an explicit login is made.
|
16
|
+
# * last_login_ip - Updates with the value of current_login_ip before it is reset.
|
13
17
|
module MagicColumns
|
14
18
|
def self.included(klass)
|
15
19
|
klass.class_eval do
|
@@ -24,10 +28,12 @@ module Authlogic
|
|
24
28
|
|
25
29
|
# Configuration for the magic columns feature.
|
26
30
|
module Config
|
27
|
-
# Every time a session is found the last_request_at field for that record is
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
+
# Every time a session is found the last_request_at field for that record is
|
32
|
+
# updated with the current time, if that field exists. If you want to limit how
|
33
|
+
# frequent that field is updated specify the threshold here. For example, if your
|
34
|
+
# user is making a request every 5 seconds, and you feel this is too frequent, and
|
35
|
+
# feel a minute is a good threshold. Set this to 1.minute. Once a minute has
|
36
|
+
# passed in between requests the field will be updated.
|
31
37
|
#
|
32
38
|
# * <tt>Default:</tt> 0
|
33
39
|
# * <tt>Accepts:</tt> integer representing time in seconds
|
@@ -40,6 +46,7 @@ module Authlogic
|
|
40
46
|
# The methods available for an Authlogic::Session::Base object that make up the magic columns feature.
|
41
47
|
module InstanceMethods
|
42
48
|
private
|
49
|
+
|
43
50
|
def increase_failed_login_count
|
44
51
|
if invalid_password? && attempted_record.respond_to?(:failed_login_count)
|
45
52
|
attempted_record.failed_login_count ||= 0
|
@@ -83,7 +90,7 @@ module Authlogic
|
|
83
90
|
# You can do whatever you want with that method.
|
84
91
|
def set_last_request_at? # :doc:
|
85
92
|
return false if !record || !klass.column_names.include?("last_request_at")
|
86
|
-
return controller.
|
93
|
+
return false if controller.responds_to_last_request_update_allowed? && !controller.last_request_update_allowed?
|
87
94
|
record.last_request_at.blank? || last_request_at_threshold.to_i.seconds.ago >= record.last_request_at
|
88
95
|
end
|
89
96
|
|
@@ -1,18 +1,25 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module Session
|
3
|
-
# Authlogic tries to check the state of the record before creating the session. If
|
3
|
+
# Authlogic tries to check the state of the record before creating the session. If
|
4
|
+
# your record responds to the following methods and any of them return false,
|
5
|
+
# validation will fail:
|
4
6
|
#
|
5
7
|
# Method name Description
|
6
8
|
# active? Is the record marked as active?
|
7
9
|
# approved? Has the record been approved?
|
8
|
-
# confirmed? Has the record been
|
10
|
+
# confirmed? Has the record been confirmed?
|
9
11
|
#
|
10
|
-
# Authlogic does nothing to define these methods for you, its up to you to define what
|
12
|
+
# Authlogic does nothing to define these methods for you, its up to you to define what
|
13
|
+
# they mean. If your object responds to these methods Authlogic will use them,
|
14
|
+
# otherwise they are ignored.
|
11
15
|
#
|
12
|
-
# What's neat about this is that these are checked upon any type of login. When
|
13
|
-
#
|
16
|
+
# What's neat about this is that these are checked upon any type of login. When
|
17
|
+
# logging in explicitly, by cookie, session, or basic http auth. So if you mark a user
|
18
|
+
# inactive in the middle of their session they wont be logged back in next time they
|
19
|
+
# refresh the page. Giving you complete control.
|
14
20
|
#
|
15
|
-
# Need Authlogic to check your own "state"? No problem, check out the hooks section
|
21
|
+
# Need Authlogic to check your own "state"? No problem, check out the hooks section
|
22
|
+
# below. Add in a before_validation to do your own checking. The sky is the limit.
|
16
23
|
module MagicStates
|
17
24
|
def self.included(klass)
|
18
25
|
klass.class_eval do
|
@@ -21,12 +28,14 @@ module Authlogic
|
|
21
28
|
validate :validate_magic_states, :unless => :disable_magic_states?
|
22
29
|
end
|
23
30
|
end
|
24
|
-
|
31
|
+
|
25
32
|
# Configuration for the magic states feature.
|
26
33
|
module Config
|
27
|
-
# Set this to true if you want to disable the checking of active?, approved?, and
|
28
|
-
#
|
29
|
-
#
|
34
|
+
# Set this to true if you want to disable the checking of active?, approved?, and
|
35
|
+
# confirmed? on your record. This is more or less of a convenience feature, since
|
36
|
+
# 99% of the time if those methods exist and return false you will not want the
|
37
|
+
# user logging in. You could easily accomplish this same thing with a
|
38
|
+
# before_validation method or other callbacks.
|
30
39
|
#
|
31
40
|
# * <tt>Default:</tt> false
|
32
41
|
# * <tt>Accepts:</tt> Boolean
|
@@ -35,14 +44,16 @@ module Authlogic
|
|
35
44
|
end
|
36
45
|
alias_method :disable_magic_states=, :disable_magic_states
|
37
46
|
end
|
38
|
-
|
39
|
-
# The methods available for an Authlogic::Session::Base object that make up the
|
47
|
+
|
48
|
+
# The methods available for an Authlogic::Session::Base object that make up the
|
49
|
+
# magic states feature.
|
40
50
|
module InstanceMethods
|
41
51
|
private
|
52
|
+
|
42
53
|
def disable_magic_states?
|
43
54
|
self.class.disable_magic_states == true
|
44
55
|
end
|
45
|
-
|
56
|
+
|
46
57
|
def validate_magic_states
|
47
58
|
return true if attempted_record.nil?
|
48
59
|
[:active, :approved, :confirmed].each do |required_status|
|
@@ -56,4 +67,4 @@ module Authlogic
|
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
59
|
-
end
|
70
|
+
end
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module Authlogic
|
2
2
|
module Session
|
3
|
-
# This module is responsible for authenticating the user via params, which ultimately
|
3
|
+
# This module is responsible for authenticating the user via params, which ultimately
|
4
|
+
# allows the user to log in using a URL like the following:
|
4
5
|
#
|
5
6
|
# https://www.domain.com?user_credentials=4LiXF7FiGUppIPubBPey
|
6
7
|
#
|
7
|
-
# Notice the token in the URL, this is a single access token. A single access token is
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# Notice the token in the URL, this is a single access token. A single access token is
|
9
|
+
# used for single access only, it is not persisted. Meaning the user provides it,
|
10
|
+
# Authlogic grants them access, and that's it. If they want access again they need to
|
11
|
+
# provide the token again. Authlogic will *NEVER* try to persist the session after
|
12
|
+
# authenticating through this method.
|
10
13
|
#
|
11
|
-
# For added security, this token is *ONLY* allowed for RSS and ATOM requests. You can
|
12
|
-
#
|
14
|
+
# For added security, this token is *ONLY* allowed for RSS and ATOM requests. You can
|
15
|
+
# change this with the configuration. You can also define if it is allowed dynamically
|
16
|
+
# by defining a single_access_allowed? method in your controller. For example:
|
13
17
|
#
|
14
18
|
# class UsersController < ApplicationController
|
15
19
|
# private
|
@@ -17,8 +21,9 @@ module Authlogic
|
|
17
21
|
# action_name == "index"
|
18
22
|
# end
|
19
23
|
#
|
20
|
-
# Also, by default, this token is permanent. Meaning if the user changes their
|
21
|
-
# when it is explicitly
|
24
|
+
# Also, by default, this token is permanent. Meaning if the user changes their
|
25
|
+
# password, this token will remain the same. It will only change when it is explicitly
|
26
|
+
# reset.
|
22
27
|
#
|
23
28
|
# You can modify all of this behavior with the Config sub module.
|
24
29
|
module Params
|
@@ -30,15 +35,19 @@ module Authlogic
|
|
30
35
|
persist :persist_by_params
|
31
36
|
end
|
32
37
|
end
|
33
|
-
|
38
|
+
|
34
39
|
# Configuration for the params / single access feature.
|
35
40
|
module Config
|
36
|
-
# Works exactly like cookie_key, but for params. So a user can login via
|
41
|
+
# Works exactly like cookie_key, but for params. So a user can login via
|
42
|
+
# params just like a cookie or a session. Your URL would look like:
|
37
43
|
#
|
38
44
|
# http://www.domain.com?user_credentials=my_single_access_key
|
39
45
|
#
|
40
|
-
# You can change the "user_credentials" key above with this
|
41
|
-
#
|
46
|
+
# You can change the "user_credentials" key above with this
|
47
|
+
# configuration option. Keep in mind, just like cookie_key, if you
|
48
|
+
# supply an id the id will be appended to the front. Check out
|
49
|
+
# cookie_key for more details. Also checkout the "Single Access /
|
50
|
+
# Private Feeds Access" section in the README.
|
42
51
|
#
|
43
52
|
# * <tt>Default:</tt> cookie_key
|
44
53
|
# * <tt>Accepts:</tt> String
|
@@ -46,56 +55,62 @@ module Authlogic
|
|
46
55
|
rw_config(:params_key, value, cookie_key)
|
47
56
|
end
|
48
57
|
alias_method :params_key=, :params_key
|
49
|
-
|
50
|
-
# Authentication is allowed via a single access token, but maybe this is
|
51
|
-
# something you
|
58
|
+
|
59
|
+
# Authentication is allowed via a single access token, but maybe this is
|
60
|
+
# something you don't want for your application as a whole. Maybe this
|
61
|
+
# is something you only want for specific request types. Specify a list
|
62
|
+
# of allowed request types and single access authentication will only be
|
52
63
|
# allowed for the ones you specify.
|
53
64
|
#
|
54
65
|
# * <tt>Default:</tt> ["application/rss+xml", "application/atom+xml"]
|
55
|
-
# * <tt>Accepts:</tt> String of a request type, or :all or :any to
|
66
|
+
# * <tt>Accepts:</tt> String of a request type, or :all or :any to
|
67
|
+
# allow single access authentication for any and all request types
|
56
68
|
def single_access_allowed_request_types(value = nil)
|
57
69
|
rw_config(:single_access_allowed_request_types, value, ["application/rss+xml", "application/atom+xml"])
|
58
70
|
end
|
59
71
|
alias_method :single_access_allowed_request_types=, :single_access_allowed_request_types
|
60
72
|
end
|
61
|
-
|
62
|
-
# The methods available for an Authlogic::Session::Base object that make
|
73
|
+
|
74
|
+
# The methods available for an Authlogic::Session::Base object that make
|
75
|
+
# up the params / single access feature.
|
63
76
|
module InstanceMethods
|
64
77
|
private
|
78
|
+
|
65
79
|
def persist_by_params
|
66
80
|
return false if !params_enabled?
|
67
81
|
self.unauthorized_record = search_for_record("find_by_single_access_token", params_credentials)
|
68
82
|
self.single_access = valid?
|
69
83
|
end
|
70
|
-
|
84
|
+
|
71
85
|
def params_enabled?
|
72
86
|
return false if !params_credentials || !klass.column_names.include?("single_access_token")
|
73
87
|
return controller.single_access_allowed? if controller.responds_to_single_access_allowed?
|
74
|
-
|
88
|
+
|
75
89
|
case single_access_allowed_request_types
|
76
90
|
when Array
|
77
|
-
single_access_allowed_request_types.include?(controller.request_content_type) ||
|
91
|
+
single_access_allowed_request_types.include?(controller.request_content_type) ||
|
92
|
+
single_access_allowed_request_types.include?(:all)
|
78
93
|
else
|
79
94
|
[:all, :any].include?(single_access_allowed_request_types)
|
80
95
|
end
|
81
96
|
end
|
82
|
-
|
97
|
+
|
83
98
|
def params_key
|
84
99
|
build_key(self.class.params_key)
|
85
100
|
end
|
86
|
-
|
101
|
+
|
87
102
|
def single_access?
|
88
103
|
single_access == true
|
89
104
|
end
|
90
|
-
|
105
|
+
|
91
106
|
def single_access_allowed_request_types
|
92
107
|
self.class.single_access_allowed_request_types
|
93
108
|
end
|
94
|
-
|
109
|
+
|
95
110
|
def params_credentials
|
96
111
|
controller.params[params_key]
|
97
112
|
end
|
98
113
|
end
|
99
114
|
end
|
100
115
|
end
|
101
|
-
end
|
116
|
+
end
|