sorcery 0.5.21 → 0.6.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.
- data/README.rdoc +9 -1
- data/VERSION +1 -1
- data/lib/sorcery/controller/submodules/activity_logging.rb +11 -7
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +8 -5
- data/lib/sorcery/controller/submodules/external.rb +11 -6
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +11 -6
- data/lib/sorcery/controller/submodules/remember_me.rb +14 -5
- data/lib/sorcery/controller/submodules/session_timeout.rb +3 -1
- data/lib/sorcery/controller.rb +12 -9
- data/lib/sorcery/crypto_providers/aes256.rb +8 -5
- data/lib/sorcery/crypto_providers/bcrypt.rb +12 -6
- data/lib/sorcery/crypto_providers/sha256.rb +2 -1
- data/lib/sorcery/crypto_providers/sha512.rb +2 -1
- data/lib/sorcery/initializers/initializer.rb +125 -36
- data/lib/sorcery/model/adapters/active_record.rb +2 -2
- data/lib/sorcery/model/adapters/mongoid.rb +4 -4
- data/lib/sorcery/model/submodules/activity_logging.rb +7 -6
- data/lib/sorcery/model/submodules/brute_force_protection.rb +10 -6
- data/lib/sorcery/model/submodules/external.rb +4 -2
- data/lib/sorcery/model/submodules/remember_me.rb +4 -3
- data/lib/sorcery/model/submodules/reset_password.rb +16 -8
- data/lib/sorcery/model/submodules/user_activation.rb +23 -10
- data/lib/sorcery/model/temporary_token.rb +3 -2
- data/lib/sorcery/model.rb +58 -26
- data/lib/sorcery/test_helpers/internal/rails.rb +6 -2
- data/lib/sorcery/test_helpers/internal/sinatra.rb +1 -1
- data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +1 -1
- data/lib/sorcery/test_helpers/internal.rb +2 -1
- data/sorcery.gemspec +20 -2
- data/spec/Gemfile.lock +1 -1
- data/spec/rails3/Gemfile.lock +1 -1
- data/spec/rails3/spec/controller_oauth2_spec.rb +3 -24
- data/spec/rails3/spec/controller_oauth_spec.rb +3 -24
- data/spec/rails3/spec/controller_spec.rb +2 -2
- data/spec/rails3/spec/user_activation_spec.rb +2 -168
- data/spec/rails3/spec/user_activity_logging_spec.rb +2 -30
- data/spec/rails3/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3/spec/user_oauth_spec.rb +2 -26
- data/spec/rails3/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3/spec/user_reset_password_spec.rb +3 -168
- data/spec/rails3/spec/user_spec.rb +3 -283
- data/spec/rails3_mongoid/Gemfile.lock +1 -1
- data/spec/rails3_mongoid/app/models/authentication.rb +3 -3
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +2 -171
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +2 -25
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +2 -35
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +2 -28
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +2 -45
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +2 -176
- data/spec/rails3_mongoid/spec/user_spec.rb +3 -285
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +37 -0
- data/spec/shared_examples/controller_oauth_shared_examples.rb +37 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +173 -0
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +27 -0
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +37 -0
- data/spec/shared_examples/user_oauth_shared_examples.rb +31 -0
- data/spec/shared_examples/user_remember_me_shared_examples.rb +47 -0
- data/spec/shared_examples/user_reset_password_shared_examples.rb +177 -0
- data/spec/shared_examples/user_shared_examples.rb +292 -0
- data/spec/sinatra/Gemfile.lock +1 -1
- data/spec/sinatra/spec/controller_oauth2_spec.rb +3 -24
- data/spec/sinatra/spec/controller_oauth_spec.rb +3 -24
- data/spec/sinatra/spec/controller_spec.rb +2 -2
- data/spec/sinatra_modular/Gemfile.lock +1 -1
- data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +3 -24
- data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +3 -24
- data/spec/sinatra_modular/spec_modular/controller_spec.rb +2 -2
- metadata +20 -2
|
@@ -19,8 +19,8 @@ module Sorcery
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def find_by_provider_and_uid(provider, uid)
|
|
22
|
-
user_klass
|
|
23
|
-
where(user_klass.sorcery_config.provider_attribute_name => provider, user_klass.sorcery_config.provider_uid_attribute_name => uid).first
|
|
22
|
+
@user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
|
|
23
|
+
where(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid).first
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def find_by_id(id)
|
|
@@ -43,7 +43,7 @@ module Sorcery
|
|
|
43
43
|
tap(&blk)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
def
|
|
46
|
+
def find_by_sorcery_token(token_attr_name, token)
|
|
47
47
|
where(token_attr_name => token).first
|
|
48
48
|
end
|
|
49
49
|
|
|
@@ -61,4 +61,4 @@ module Sorcery
|
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
end
|
|
64
|
-
end
|
|
64
|
+
end
|
|
@@ -3,8 +3,8 @@ module Sorcery
|
|
|
3
3
|
module Submodules
|
|
4
4
|
# This submodule keeps track of events such as login, logout, and last activity time, per user.
|
|
5
5
|
# It helps in estimating which users are active now in the site.
|
|
6
|
-
# This cannot be determined absolutely because a user might be reading a page without clicking anything
|
|
7
|
-
|
|
6
|
+
# This cannot be determined absolutely because a user might be reading a page without clicking anything
|
|
7
|
+
# for a while.
|
|
8
8
|
# This is the model part of the submodule, which provides configuration options.
|
|
9
9
|
module ActivityLogging
|
|
10
10
|
def self.included(base)
|
|
@@ -14,7 +14,8 @@ module Sorcery
|
|
|
14
14
|
attr_accessor :last_login_at_attribute_name, # last login attribute name.
|
|
15
15
|
:last_logout_at_attribute_name, # last logout attribute name.
|
|
16
16
|
:last_activity_at_attribute_name, # last activity attribute name.
|
|
17
|
-
:activity_timeout # how long since last activity is
|
|
17
|
+
:activity_timeout # how long since last activity is
|
|
18
|
+
#the user defined logged out?
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
base.sorcery_config.instance_eval do
|
|
@@ -38,9 +39,9 @@ module Sorcery
|
|
|
38
39
|
protected
|
|
39
40
|
|
|
40
41
|
def define_activity_logging_mongoid_fields
|
|
41
|
-
field sorcery_config.last_login_at_attribute_name,
|
|
42
|
-
field sorcery_config.last_logout_at_attribute_name,
|
|
43
|
-
field sorcery_config.last_activity_at_attribute_name, type
|
|
42
|
+
field sorcery_config.last_login_at_attribute_name, :type => DateTime
|
|
43
|
+
field sorcery_config.last_logout_at_attribute_name, :type => DateTime
|
|
44
|
+
field sorcery_config.last_activity_at_attribute_name, :type => DateTime
|
|
44
45
|
end
|
|
45
46
|
end
|
|
46
47
|
end
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module Model
|
|
3
3
|
module Submodules
|
|
4
|
-
# This module helps protect user accounts by locking them down after too many failed attemps
|
|
5
|
-
#
|
|
4
|
+
# This module helps protect user accounts by locking them down after too many failed attemps
|
|
5
|
+
# to login were detected.
|
|
6
|
+
# This is the model part of the submodule which provides configuration options and methods
|
|
7
|
+
# for locking and unlocking the user.
|
|
6
8
|
module BruteForceProtection
|
|
7
9
|
def self.included(base)
|
|
8
10
|
base.sorcery_config.class_eval do
|
|
9
11
|
attr_accessor :failed_logins_count_attribute_name, # failed logins attribute name.
|
|
10
|
-
:lock_expires_at_attribute_name, # this field indicates whether user
|
|
12
|
+
:lock_expires_at_attribute_name, # this field indicates whether user
|
|
13
|
+
# is banned and when it will be active again.
|
|
11
14
|
:consecutive_login_retries_amount_limit, # how many failed logins allowed.
|
|
12
|
-
:login_lock_time_period # how long the user should be banned.
|
|
15
|
+
:login_lock_time_period # how long the user should be banned.
|
|
16
|
+
# in seconds. 0 for permanent.
|
|
13
17
|
end
|
|
14
18
|
|
|
15
19
|
base.sorcery_config.instance_eval do
|
|
@@ -30,8 +34,8 @@ module Sorcery
|
|
|
30
34
|
protected
|
|
31
35
|
|
|
32
36
|
def define_brute_force_protection_mongoid_fields
|
|
33
|
-
field sorcery_config.failed_logins_count_attribute_name,
|
|
34
|
-
field sorcery_config.lock_expires_at_attribute_name,
|
|
37
|
+
field sorcery_config.failed_logins_count_attribute_name, :type => Integer
|
|
38
|
+
field sorcery_config.lock_expires_at_attribute_name, :type => DateTime
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
|
|
@@ -5,9 +5,11 @@ module Sorcery
|
|
|
5
5
|
# This is the model part which handles finding the user using access tokens.
|
|
6
6
|
# For the controller options see Sorcery::Controller::External.
|
|
7
7
|
#
|
|
8
|
-
# Socery assumes (read: requires) you will create external users in the same table where
|
|
8
|
+
# Socery assumes (read: requires) you will create external users in the same table where
|
|
9
|
+
# you keep your regular users,
|
|
9
10
|
# but that you will have a separate table for keeping their external authentication data,
|
|
10
|
-
# and that that separate table has a few rows for each user, facebook and twitter
|
|
11
|
+
# and that that separate table has a few rows for each user, facebook and twitter
|
|
12
|
+
# for example (a one-to-many relationship).
|
|
11
13
|
#
|
|
12
14
|
# External users will have a null crypted_password field, since we do not hold their password.
|
|
13
15
|
# They will not be sent activation emails on creation.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module Model
|
|
3
3
|
module Submodules
|
|
4
|
-
# The Remember Me submodule takes care of setting the user's cookie so that he will
|
|
4
|
+
# The Remember Me submodule takes care of setting the user's cookie so that he will
|
|
5
|
+
# be automatically logged in to the site on every visit,
|
|
5
6
|
# until the cookie expires.
|
|
6
7
|
module RememberMe
|
|
7
8
|
def self.included(base)
|
|
@@ -31,8 +32,8 @@ module Sorcery
|
|
|
31
32
|
protected
|
|
32
33
|
|
|
33
34
|
def define_remember_me_mongoid_fields
|
|
34
|
-
field sorcery_config.remember_me_token_attribute_name,
|
|
35
|
-
field sorcery_config.remember_me_token_expires_at_attribute_name, type
|
|
35
|
+
field sorcery_config.remember_me_token_attribute_name, :type => String
|
|
36
|
+
field sorcery_config.remember_me_token_expires_at_attribute_name, :type => Time
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
end
|
|
@@ -5,7 +5,8 @@ module Sorcery
|
|
|
5
5
|
# When the user requests an email is sent to him with a url.
|
|
6
6
|
# The url includes a token, which is also saved with the user's record in the db.
|
|
7
7
|
# The token has configurable expiration.
|
|
8
|
-
# When the user clicks the url in the email, providing the token has not yet expired,
|
|
8
|
+
# When the user clicks the url in the email, providing the token has not yet expired,
|
|
9
|
+
# he will be able to reset his password via a form.
|
|
9
10
|
#
|
|
10
11
|
# When using this submodule, supplying a mailer is mandatory.
|
|
11
12
|
module ResetPassword
|
|
@@ -13,11 +14,18 @@ module Sorcery
|
|
|
13
14
|
base.sorcery_config.class_eval do
|
|
14
15
|
attr_accessor :reset_password_token_attribute_name, # reset password code attribute name.
|
|
15
16
|
:reset_password_token_expires_at_attribute_name, # expires at attribute name.
|
|
16
|
-
:reset_password_email_sent_at_attribute_name, # when was email sent, used for hammering
|
|
17
|
+
:reset_password_email_sent_at_attribute_name, # when was email sent, used for hammering
|
|
18
|
+
# protection.
|
|
19
|
+
|
|
17
20
|
:reset_password_mailer, # mailer class. Needed.
|
|
18
|
-
:reset_password_email_method_name, # reset password email method on your
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
:reset_password_email_method_name, # reset password email method on your
|
|
22
|
+
# mailer class.
|
|
23
|
+
|
|
24
|
+
:reset_password_expiration_period, # how many seconds before the reset request
|
|
25
|
+
# expires. nil for never expires.
|
|
26
|
+
|
|
27
|
+
:reset_password_time_between_emails # hammering protection, how long to wait
|
|
28
|
+
# before allowing another email to be sent.
|
|
21
29
|
|
|
22
30
|
end
|
|
23
31
|
|
|
@@ -61,9 +69,9 @@ module Sorcery
|
|
|
61
69
|
end
|
|
62
70
|
|
|
63
71
|
def define_reset_password_mongoid_fields
|
|
64
|
-
field sorcery_config.reset_password_token_attribute_name,
|
|
65
|
-
field sorcery_config.reset_password_token_expires_at_attribute_name,
|
|
66
|
-
field sorcery_config.reset_password_email_sent_at_attribute_name,
|
|
72
|
+
field sorcery_config.reset_password_token_attribute_name, :type => String
|
|
73
|
+
field sorcery_config.reset_password_token_expires_at_attribute_name, :type => DateTime
|
|
74
|
+
field sorcery_config.reset_password_email_sent_at_attribute_name, :type => DateTime
|
|
67
75
|
end
|
|
68
76
|
end
|
|
69
77
|
|
|
@@ -8,14 +8,27 @@ module Sorcery
|
|
|
8
8
|
module UserActivation
|
|
9
9
|
def self.included(base)
|
|
10
10
|
base.sorcery_config.class_eval do
|
|
11
|
-
attr_accessor :activation_state_attribute_name, # the attribute name to hold activation state
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
:
|
|
11
|
+
attr_accessor :activation_state_attribute_name, # the attribute name to hold activation state
|
|
12
|
+
# (active/pending).
|
|
13
|
+
|
|
14
|
+
:activation_token_attribute_name, # the attribute name to hold activation code
|
|
15
|
+
# (sent by email).
|
|
16
|
+
|
|
17
|
+
:activation_token_expires_at_attribute_name, # the attribute name to hold activation code
|
|
18
|
+
# expiration date.
|
|
19
|
+
|
|
20
|
+
:activation_token_expiration_period, # how many seconds before the activation code
|
|
21
|
+
# expires. nil for never expires.
|
|
22
|
+
|
|
15
23
|
:user_activation_mailer, # your mailer class. Required.
|
|
16
|
-
:activation_needed_email_method_name, # activation needed email method on your
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
:activation_needed_email_method_name, # activation needed email method on your
|
|
25
|
+
# mailer class.
|
|
26
|
+
|
|
27
|
+
:activation_success_email_method_name, # activation success email method on your
|
|
28
|
+
# mailer class.
|
|
29
|
+
|
|
30
|
+
:prevent_non_active_users_to_login # do you want to prevent or allow users that
|
|
31
|
+
# did not activate by email to login?
|
|
19
32
|
end
|
|
20
33
|
|
|
21
34
|
base.sorcery_config.instance_eval do
|
|
@@ -67,9 +80,9 @@ module Sorcery
|
|
|
67
80
|
|
|
68
81
|
def define_user_activation_mongoid_fields
|
|
69
82
|
self.class_eval do
|
|
70
|
-
field sorcery_config.activation_state_attribute_name,
|
|
71
|
-
field sorcery_config.activation_token_attribute_name,
|
|
72
|
-
field sorcery_config.activation_token_expires_at_attribute_name, type
|
|
83
|
+
field sorcery_config.activation_state_attribute_name, :type => String
|
|
84
|
+
field sorcery_config.activation_token_attribute_name, :type => String
|
|
85
|
+
field sorcery_config.activation_token_expires_at_attribute_name, :type => DateTime
|
|
73
86
|
end
|
|
74
87
|
end
|
|
75
88
|
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
module Sorcery
|
|
2
2
|
module Model
|
|
3
3
|
# This module encapsulates the logic for temporary token.
|
|
4
|
-
# A temporary token is created to identify a user in scenarios
|
|
4
|
+
# A temporary token is created to identify a user in scenarios
|
|
5
|
+
# such as reseting password and activating the user by email.
|
|
5
6
|
module TemporaryToken
|
|
6
7
|
def self.included(base)
|
|
7
8
|
base.extend(ClassMethods)
|
|
@@ -10,7 +11,7 @@ module Sorcery
|
|
|
10
11
|
module ClassMethods
|
|
11
12
|
def load_from_token(token, token_attr_name, token_expiration_date_attr)
|
|
12
13
|
return nil if token.blank?
|
|
13
|
-
user =
|
|
14
|
+
user = find_by_sorcery_token(token_attr_name,token)
|
|
14
15
|
if !user.blank? && !user.send(token_expiration_date_attr).nil?
|
|
15
16
|
return Time.now.utc < user.send(token_expiration_date_attr) ? user : nil
|
|
16
17
|
end
|
data/lib/sorcery/model.rb
CHANGED
|
@@ -3,7 +3,8 @@ module Sorcery
|
|
|
3
3
|
# It should be included into the ORM base class.
|
|
4
4
|
# In the case of Rails this is usually ActiveRecord (actually, in that case, the plugin does this automatically).
|
|
5
5
|
#
|
|
6
|
-
# When included it defines a single method: 'activate_sorcery!' which when called adds the other capabilities
|
|
6
|
+
# When included it defines a single method: 'activate_sorcery!' which when called adds the other capabilities
|
|
7
|
+
# to the class.
|
|
7
8
|
# This method is also the place to configure the plugin in the Model layer.
|
|
8
9
|
module Model
|
|
9
10
|
def self.included(klass)
|
|
@@ -14,39 +15,58 @@ module Sorcery
|
|
|
14
15
|
self.class_eval do
|
|
15
16
|
extend ClassMethods # included here, before submodules, so they can be overriden by them.
|
|
16
17
|
include InstanceMethods
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
include_required_submodules!
|
|
21
|
+
|
|
22
|
+
# This runs the options block set in the initializer on the model class.
|
|
23
|
+
::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
|
|
24
|
+
|
|
25
|
+
init_mongoid_support! if defined?(Mongoid) and self.ancestors.include?(Mongoid::Document)
|
|
17
26
|
|
|
27
|
+
init_orm_hooks!
|
|
28
|
+
|
|
29
|
+
@sorcery_config.after_config << :add_config_inheritance if @sorcery_config.subclasses_inherit_config
|
|
30
|
+
@sorcery_config.after_config.each { |c| send(c) }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
protected
|
|
34
|
+
|
|
35
|
+
# includes required submodules into the model class,
|
|
36
|
+
# which usually is called User.
|
|
37
|
+
def include_required_submodules!
|
|
38
|
+
self.class_eval do
|
|
18
39
|
@sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
|
|
19
40
|
@sorcery_config.submodules.each do |mod|
|
|
20
41
|
begin
|
|
21
42
|
include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
|
|
22
43
|
rescue NameError
|
|
23
|
-
# don't stop on a missing submodule. Needed because some submodules are only defined
|
|
44
|
+
# don't stop on a missing submodule. Needed because some submodules are only defined
|
|
45
|
+
# in the controller side.
|
|
24
46
|
end
|
|
25
47
|
end
|
|
26
48
|
end
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# defines mongoid fields on the model class,
|
|
52
|
+
# using 1.8.x hash syntax to perserve compatibility.
|
|
53
|
+
def init_mongoid_support!
|
|
32
54
|
self.class_eval do
|
|
33
|
-
field sorcery_config.username_attribute_name,
|
|
34
|
-
|
|
35
|
-
field sorcery_config.
|
|
36
|
-
field sorcery_config.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
field sorcery_config.username_attribute_name, :type => String
|
|
56
|
+
field sorcery_config.email_attribute_name, :type => String unless sorcery_config.username_attribute_name == sorcery_config.email_attribute_name
|
|
57
|
+
field sorcery_config.crypted_password_attribute_name, :type => String
|
|
58
|
+
field sorcery_config.salt_attribute_name, :type => String
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# add virtual password accessor and ORM callbacks.
|
|
63
|
+
def init_orm_hooks!
|
|
41
64
|
self.class_eval do
|
|
42
65
|
attr_accessor @sorcery_config.password_attribute_name
|
|
43
66
|
attr_protected @sorcery_config.crypted_password_attribute_name, @sorcery_config.salt_attribute_name
|
|
44
67
|
before_save :encrypt_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? }
|
|
45
68
|
after_save :clear_virtual_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? }
|
|
46
69
|
end
|
|
47
|
-
|
|
48
|
-
@sorcery_config.after_config << :add_config_inheritance if @sorcery_config.subclasses_inherit_config
|
|
49
|
-
@sorcery_config.after_config.each { |c| send(c) }
|
|
50
70
|
end
|
|
51
71
|
end
|
|
52
72
|
end
|
|
@@ -147,26 +167,38 @@ module Sorcery
|
|
|
147
167
|
end
|
|
148
168
|
|
|
149
169
|
# Each class which calls 'activate_sorcery!' receives an instance of this class.
|
|
150
|
-
# Every submodule which gets loaded may add accessors to this class so that all
|
|
170
|
+
# Every submodule which gets loaded may add accessors to this class so that all
|
|
171
|
+
# options will be configured from a single place.
|
|
151
172
|
class Config
|
|
152
173
|
|
|
153
|
-
attr_accessor :username_attribute_name, # change default username attribute, for example, to use :email
|
|
154
|
-
|
|
174
|
+
attr_accessor :username_attribute_name, # change default username attribute, for example, to use :email
|
|
175
|
+
# as the login.
|
|
176
|
+
|
|
177
|
+
:password_attribute_name, # change *virtual* password attribute, the one which is used
|
|
178
|
+
# until an encrypted one is generated.
|
|
179
|
+
|
|
155
180
|
:email_attribute_name, # change default email attribute.
|
|
156
181
|
:crypted_password_attribute_name, # change default crypted_password attribute.
|
|
157
182
|
:salt_join_token, # what pattern to use to join the password with the salt
|
|
158
183
|
:salt_attribute_name, # change default salt attribute.
|
|
159
184
|
:stretches, # how many times to apply encryption to the password.
|
|
160
|
-
:encryption_key, # encryption key used to encrypt reversible encryptions such as
|
|
161
|
-
|
|
185
|
+
:encryption_key, # encryption key used to encrypt reversible encryptions such as
|
|
186
|
+
# AES256.
|
|
187
|
+
|
|
188
|
+
:subclasses_inherit_config, # make this configuration inheritable for subclasses. Useful for
|
|
189
|
+
# ActiveRecord's STI.
|
|
162
190
|
|
|
163
191
|
:submodules, # configured in config/application.rb
|
|
164
|
-
:before_authenticate, # an array of method names to call before authentication
|
|
165
|
-
|
|
192
|
+
:before_authenticate, # an array of method names to call before authentication
|
|
193
|
+
# completes. used internally.
|
|
194
|
+
|
|
195
|
+
:after_config # an array of method names to call after configuration by user.
|
|
196
|
+
# used internally.
|
|
166
197
|
|
|
167
198
|
attr_reader :encryption_provider, # change default encryption_provider.
|
|
168
199
|
:custom_encryption_provider, # use an external encryption class.
|
|
169
|
-
:encryption_algorithm # encryption algorithm name. See 'encryption_algorithm=' below
|
|
200
|
+
:encryption_algorithm # encryption algorithm name. See 'encryption_algorithm=' below
|
|
201
|
+
# for available options.
|
|
170
202
|
|
|
171
203
|
def initialize
|
|
172
204
|
@defaults = {
|
|
@@ -4,7 +4,11 @@ module Sorcery
|
|
|
4
4
|
module Rails
|
|
5
5
|
include ::Sorcery::TestHelpers::Rails
|
|
6
6
|
|
|
7
|
-
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [
|
|
7
|
+
SUBMODUELS_AUTO_ADDED_CONTROLLER_FILTERS = [
|
|
8
|
+
:register_last_activity_time_to_db,
|
|
9
|
+
:deny_banned_user,
|
|
10
|
+
:validate_session
|
|
11
|
+
]
|
|
8
12
|
|
|
9
13
|
def sorcery_reload!(submodules = [], options = {})
|
|
10
14
|
reload_user_class
|
|
@@ -22,7 +26,7 @@ module Sorcery
|
|
|
22
26
|
::Sorcery::Controller::Config.submodules = submodules
|
|
23
27
|
::Sorcery::Controller::Config.user_class = nil
|
|
24
28
|
ActionController::Base.send(:include,::Sorcery::Controller)
|
|
25
|
-
::Sorcery::Controller::Config.user_class = User
|
|
29
|
+
::Sorcery::Controller::Config.user_class = "User"
|
|
26
30
|
|
|
27
31
|
::Sorcery::Controller::Config.user_config do |user|
|
|
28
32
|
options.each do |property,value|
|
|
@@ -51,7 +51,7 @@ module Sorcery
|
|
|
51
51
|
::Sorcery::Controller::Config.user_class = nil
|
|
52
52
|
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
53
|
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = User
|
|
54
|
+
::Sorcery::Controller::Config.user_class = "User"
|
|
55
55
|
|
|
56
56
|
::Sorcery::Controller::Config.user_config do |user|
|
|
57
57
|
options.each do |property, value|
|
|
@@ -51,7 +51,7 @@ module Sorcery
|
|
|
51
51
|
::Sorcery::Controller::Config.user_class = nil
|
|
52
52
|
::Sinatra::Base.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
53
|
::Sinatra::Base.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = User
|
|
54
|
+
::Sorcery::Controller::Config.user_class = "User"
|
|
55
55
|
|
|
56
56
|
::Sorcery::Controller::Config.user_config do |user|
|
|
57
57
|
options.each do |property, value|
|
|
@@ -15,7 +15,8 @@ module Sorcery
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# a patch to fix a bug in testing that happens when you 'destroy' a session twice.
|
|
18
|
-
# After the first destroy, the session is an ordinary hash, and then when destroy
|
|
18
|
+
# After the first destroy, the session is an ordinary hash, and then when destroy
|
|
19
|
+
# is called again there's an exception.
|
|
19
20
|
class ::Hash
|
|
20
21
|
def destroy
|
|
21
22
|
clear
|
data/sorcery.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{sorcery}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.6.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Noam Ben Ari"]
|
|
12
|
-
s.date = %q{2011-
|
|
12
|
+
s.date = %q{2011-07-30}
|
|
13
13
|
s.description = %q{Provides common authentication needs such as signing in/out, activating by email and resetting password.}
|
|
14
14
|
s.email = %q{nbenari@gmail.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -218,6 +218,15 @@ Gem::Specification.new do |s|
|
|
|
218
218
|
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
219
219
|
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
220
220
|
"spec/rails3_mongoid/vendor/plugins/.gitkeep",
|
|
221
|
+
"spec/shared_examples/controller_oauth2_shared_examples.rb",
|
|
222
|
+
"spec/shared_examples/controller_oauth_shared_examples.rb",
|
|
223
|
+
"spec/shared_examples/user_activation_shared_examples.rb",
|
|
224
|
+
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
|
225
|
+
"spec/shared_examples/user_brute_force_protection_shared_examples.rb",
|
|
226
|
+
"spec/shared_examples/user_oauth_shared_examples.rb",
|
|
227
|
+
"spec/shared_examples/user_remember_me_shared_examples.rb",
|
|
228
|
+
"spec/shared_examples/user_reset_password_shared_examples.rb",
|
|
229
|
+
"spec/shared_examples/user_shared_examples.rb",
|
|
221
230
|
"spec/sinatra/Gemfile",
|
|
222
231
|
"spec/sinatra/Gemfile.lock",
|
|
223
232
|
"spec/sinatra/Rakefile",
|
|
@@ -355,6 +364,15 @@ Gem::Specification.new do |s|
|
|
|
355
364
|
"spec/rails3_mongoid/spec/user_remember_me_spec.rb",
|
|
356
365
|
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
|
357
366
|
"spec/rails3_mongoid/spec/user_spec.rb",
|
|
367
|
+
"spec/shared_examples/controller_oauth2_shared_examples.rb",
|
|
368
|
+
"spec/shared_examples/controller_oauth_shared_examples.rb",
|
|
369
|
+
"spec/shared_examples/user_activation_shared_examples.rb",
|
|
370
|
+
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
|
371
|
+
"spec/shared_examples/user_brute_force_protection_shared_examples.rb",
|
|
372
|
+
"spec/shared_examples/user_oauth_shared_examples.rb",
|
|
373
|
+
"spec/shared_examples/user_remember_me_shared_examples.rb",
|
|
374
|
+
"spec/shared_examples/user_reset_password_shared_examples.rb",
|
|
375
|
+
"spec/shared_examples/user_shared_examples.rb",
|
|
358
376
|
"spec/sinatra/authentication.rb",
|
|
359
377
|
"spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb",
|
|
360
378
|
"spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
data/spec/Gemfile.lock
CHANGED
data/spec/rails3/Gemfile.lock
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth2_shared_examples')
|
|
2
3
|
|
|
3
4
|
def stub_all_oauth2_requests!
|
|
4
5
|
@client = OAuth2::Client.new("key","secret", :site => "http://myapi.com")
|
|
@@ -58,30 +59,8 @@ describe ApplicationController do
|
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
61
|
-
describe ApplicationController
|
|
62
|
-
|
|
63
|
-
stub_all_oauth2_requests!
|
|
64
|
-
User.delete_all
|
|
65
|
-
Authentication.delete_all
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "should create a new user" do
|
|
69
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
70
|
-
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
|
|
71
|
-
lambda do
|
|
72
|
-
get :test_create_from_provider, :provider => "facebook"
|
|
73
|
-
end.should change(User, :count).by(1)
|
|
74
|
-
User.first.username.should == "Noam Ben Ari"
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "should support nested attributes" do
|
|
78
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
79
|
-
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
|
|
80
|
-
lambda do
|
|
81
|
-
get :test_create_from_provider, :provider => "facebook"
|
|
82
|
-
end.should change(User, :count).by(1)
|
|
83
|
-
User.first.username.should == "Haifa, Israel"
|
|
84
|
-
end
|
|
62
|
+
describe ApplicationController do
|
|
63
|
+
it_behaves_like "oauth2_controller"
|
|
85
64
|
end
|
|
86
65
|
|
|
87
66
|
describe ApplicationController, "OAuth with User Activation features" do
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../shared_examples/controller_oauth_shared_examples')
|
|
2
3
|
require 'ostruct'
|
|
3
4
|
|
|
4
5
|
def stub_all_oauth_requests!
|
|
@@ -64,30 +65,8 @@ describe ApplicationController do
|
|
|
64
65
|
end
|
|
65
66
|
end
|
|
66
67
|
|
|
67
|
-
describe ApplicationController
|
|
68
|
-
|
|
69
|
-
stub_all_oauth_requests!
|
|
70
|
-
User.delete_all
|
|
71
|
-
Authentication.delete_all
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should create a new user" do
|
|
75
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
76
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
|
77
|
-
lambda do
|
|
78
|
-
get :test_create_from_provider, :provider => "twitter"
|
|
79
|
-
end.should change(User, :count).by(1)
|
|
80
|
-
User.first.username.should == "nbenari"
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it "should support nested attributes" do
|
|
84
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
|
85
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
|
86
|
-
lambda do
|
|
87
|
-
get :test_create_from_provider, :provider => "twitter"
|
|
88
|
-
end.should change(User, :count).by(1)
|
|
89
|
-
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
|
90
|
-
end
|
|
68
|
+
describe ApplicationController do
|
|
69
|
+
it_behaves_like "oauth_controller"
|
|
91
70
|
end
|
|
92
71
|
|
|
93
72
|
describe ApplicationController, "using OAuth with User Activation features" do
|
|
@@ -14,8 +14,8 @@ describe ApplicationController do
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it "should enable configuration option 'user_class'" do
|
|
17
|
-
sorcery_controller_property_set(:user_class, TestUser)
|
|
18
|
-
Sorcery::Controller::Config.user_class.should
|
|
17
|
+
sorcery_controller_property_set(:user_class, "TestUser")
|
|
18
|
+
Sorcery::Controller::Config.user_class.should == "TestUser"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
it "should enable configuration option 'not_authenticated_action'" do
|