merb-auth-more 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/merb-auth-more/mixins/bcrypt_user.rb +15 -15
- data/lib/merb-auth-more/mixins/redirect_back.rb +10 -10
- data/lib/merb-auth-more/mixins/salted_user.rb +16 -16
- data/lib/merb-auth-more/mixins/salted_user/ar_salted_user.rb +6 -6
- data/lib/merb-auth-more/mixins/salted_user/dm_salted_user.rb +5 -5
- data/lib/merb-auth-more/mixins/salted_user/mongoid_salted_user.rb +5 -5
- data/lib/merb-auth-more/mixins/salted_user/relaxdb_salted_user.rb +7 -7
- data/lib/merb-auth-more/mixins/salted_user/sq_salted_user.rb +3 -3
- data/lib/merb-auth-more/strategies/abstract_password.rb +6 -6
- data/lib/merb-auth-more/strategies/basic/basic_auth.rb +12 -12
- data/lib/merb-auth-more/strategies/basic/openid.rb +18 -18
- data/lib/merb-auth-more/strategies/basic/password_form.rb +4 -4
- data/lib/merb-auth-more/version.rb +1 -1
- data/spec/mixins/dm_salted_user_spec.rb +3 -3
- data/spec/mixins/redirect_back_spec.rb +12 -12
- data/spec/mixins/sq_bcrypt_user_spec.rb +2 -2
- data/spec/mixins/sq_salted_user_spec.rb +2 -2
- data/spec/shared_user_spec.rb +1 -1
- metadata +15 -6
@@ -4,7 +4,7 @@ require 'merb-auth-more/strategies/abstract_password'
|
|
4
4
|
class Merb::Authentication
|
5
5
|
module Mixins
|
6
6
|
# This mixin provides basic salted user password encryption.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# Added properties:
|
9
9
|
# :crypted_password, String
|
10
10
|
#
|
@@ -16,15 +16,15 @@ class Merb::Authentication
|
|
16
16
|
# end
|
17
17
|
#
|
18
18
|
module BCryptUser
|
19
|
-
|
19
|
+
|
20
20
|
def self.included(base)
|
21
|
-
base.class_eval do
|
21
|
+
base.class_eval do
|
22
22
|
attr_accessor :password, :password_confirmation
|
23
23
|
|
24
|
-
|
24
|
+
|
25
25
|
include Merb::Authentication::Mixins::BCryptUser::InstanceMethods
|
26
26
|
|
27
|
-
|
27
|
+
|
28
28
|
path = File.expand_path(File.dirname(__FILE__)) / "salted_user"
|
29
29
|
if defined?(DataMapper) && DataMapper::Resource > self
|
30
30
|
require path / "dm_salted_user"
|
@@ -39,34 +39,34 @@ class Merb::Authentication
|
|
39
39
|
require path / "relaxdb_salted_user"
|
40
40
|
extend(Merb::Authentication::Mixins::SaltedUser::RDBClassMethods)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
end # base.class_eval
|
44
44
|
end # self.included
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
|
47
47
|
module InstanceMethods
|
48
|
-
|
48
|
+
|
49
49
|
def authenticated?(password)
|
50
50
|
bcrypt_password == password
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def bcrypt_password
|
54
54
|
@bcrypt_password ||= BCrypt::Password.new(crypted_password)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def password_required?
|
58
58
|
crypted_password.blank? || !password.blank?
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def encrypt_password
|
62
62
|
return if password.blank?
|
63
63
|
cost = Merb::Plugins.config[:"merb-auth"][:bcrypt_cost] || BCrypt::Engine::DEFAULT_COST
|
64
64
|
self.crypted_password = BCrypt::Password.create(password, :cost => cost)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
end # InstanceMethods
|
68
|
-
|
69
|
-
end # SaltedUser
|
68
|
+
|
69
|
+
end # SaltedUser
|
70
70
|
end # Mixins
|
71
71
|
end # Merb::Authentication
|
72
72
|
|
@@ -1,21 +1,21 @@
|
|
1
1
|
# Impelments redirect_back_or. i.e. remembers where you've come from on a failed login
|
2
2
|
# and stores this inforamtion in the session. When you're finally logged in you can use
|
3
3
|
# the redirect_back_or helper to redirect them either back where they came from, or a pre-defined url.
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# Here's some examples:
|
6
6
|
#
|
7
7
|
# 1. User visits login form and is logged in
|
8
8
|
# - redirect to the provided (default) url
|
9
9
|
#
|
10
10
|
# 2. User vists a page (/page) and gets kicked to login (raised Unauthenticated)
|
11
|
-
# - On successful login, the user may be redirect_back_or("/home") and they will
|
11
|
+
# - On successful login, the user may be redirect_back_or("/home") and they will
|
12
12
|
# return to the /page url. The /home url is ignored
|
13
13
|
#
|
14
14
|
#
|
15
15
|
|
16
16
|
#
|
17
17
|
module Merb::AuthenticatedHelper
|
18
|
-
|
18
|
+
|
19
19
|
# Add a helper to do the redirect_back_or for you. Also tidies up the session afterwards
|
20
20
|
# If there has been a failed login attempt on some page using this method
|
21
21
|
# you'll be redirected back to that page. Otherwise redirect to the default_url
|
@@ -33,21 +33,21 @@ module Merb::AuthenticatedHelper
|
|
33
33
|
end
|
34
34
|
"Redirecting to <a href='#{default_url}'>#{default_url}</a>"
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
end
|
38
38
|
|
39
39
|
# This mixin is mixed into the Exceptions controller to setup the correct methods
|
40
|
-
# And filters. It is implemented as a mixin so that it is completely overwritable in
|
40
|
+
# And filters. It is implemented as a mixin so that it is completely overwritable in
|
41
41
|
# your controllers
|
42
42
|
module Merb::Authentication::Mixins
|
43
43
|
module RedirectBack
|
44
44
|
def self.included(base)
|
45
|
-
base.class_eval do
|
45
|
+
base.class_eval do
|
46
46
|
after :_set_return_to, :only => :unauthenticated
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
50
|
-
private
|
49
|
+
|
50
|
+
private
|
51
51
|
def _set_return_to
|
52
52
|
unless request.exceptions.blank?
|
53
53
|
session[:return_to] ||= []
|
@@ -64,11 +64,11 @@ Merb::BootLoader.after_app_loads do
|
|
64
64
|
Merb::Authentication.maintain_session_keys << :return_to
|
65
65
|
end
|
66
66
|
# class Merb::Authentication
|
67
|
-
#
|
67
|
+
#
|
68
68
|
# def return_to_url
|
69
69
|
# @return_to_url ||= session[:return_to]
|
70
70
|
# end
|
71
|
-
#
|
71
|
+
#
|
72
72
|
# def return_to_url=(return_url)
|
73
73
|
# @return_to_url = session[:return_to] = return_url
|
74
74
|
# end
|
@@ -4,7 +4,7 @@ require 'merb-auth-more/strategies/abstract_password'
|
|
4
4
|
class Merb::Authentication
|
5
5
|
module Mixins
|
6
6
|
# This mixin provides basic salted user password encryption.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# Added properties:
|
9
9
|
# :crypted_password, String
|
10
10
|
# :salt, String
|
@@ -17,14 +17,14 @@ class Merb::Authentication
|
|
17
17
|
# end
|
18
18
|
#
|
19
19
|
module SaltedUser
|
20
|
-
|
20
|
+
|
21
21
|
def self.included(base)
|
22
|
-
base.class_eval do
|
22
|
+
base.class_eval do
|
23
23
|
attr_accessor :password, :password_confirmation
|
24
|
-
|
24
|
+
|
25
25
|
include Merb::Authentication::Mixins::SaltedUser::InstanceMethods
|
26
26
|
extend Merb::Authentication::Mixins::SaltedUser::ClassMethods
|
27
|
-
|
27
|
+
|
28
28
|
path = "merb-auth-more/mixins/salted_user"
|
29
29
|
if defined?(DataMapper) && DataMapper::Resource > self
|
30
30
|
require "#{path}/dm_salted_user"
|
@@ -42,40 +42,40 @@ class Merb::Authentication
|
|
42
42
|
require "#{path}/relaxdb_salted_user"
|
43
43
|
extend(Merb::Authentication::Mixins::SaltedUser::RDBClassMethods)
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
end # base.class_eval
|
47
47
|
end # self.included
|
48
|
-
|
49
|
-
|
48
|
+
|
49
|
+
|
50
50
|
module ClassMethods
|
51
51
|
# Encrypts some data with the salt.
|
52
52
|
def encrypt(password, salt)
|
53
53
|
Digest::SHA1.hexdigest("--#{salt}--#{password}--")
|
54
54
|
end
|
55
|
-
end
|
56
|
-
|
55
|
+
end
|
56
|
+
|
57
57
|
module InstanceMethods
|
58
58
|
def authenticated?(password)
|
59
59
|
crypted_password == encrypt(password)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
def encrypt(password)
|
63
63
|
self.class.encrypt(password, salt)
|
64
64
|
end
|
65
|
-
|
65
|
+
|
66
66
|
def password_required?
|
67
67
|
crypted_password.blank? || !password.blank?
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def encrypt_password
|
71
71
|
return if password.blank?
|
72
72
|
self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{Merb::Authentication::Strategies::Basic::Base.login_param}--") if salt.blank?
|
73
73
|
self.crypted_password = encrypt(password)
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
end # InstanceMethods
|
77
|
-
|
78
|
-
end # SaltedUser
|
77
|
+
|
78
|
+
end # SaltedUser
|
79
79
|
end # Mixins
|
80
80
|
end # Merb::Authentication
|
81
81
|
|
@@ -2,19 +2,19 @@ class Merb::Authentication
|
|
2
2
|
module Mixins
|
3
3
|
module SaltedUser
|
4
4
|
module ARClassMethods
|
5
|
-
|
5
|
+
|
6
6
|
def self.extended(base)
|
7
7
|
base.class_eval do
|
8
|
-
|
8
|
+
|
9
9
|
validates_presence_of :password, :if => :password_required?
|
10
10
|
validates_presence_of :password_confirmation, :if => :password_required?
|
11
11
|
validates_confirmation_of :password, :if => :password_required?
|
12
|
-
|
12
|
+
|
13
13
|
before_save :encrypt_password
|
14
14
|
end # base.class_eval
|
15
|
-
|
15
|
+
|
16
16
|
end # self.extended
|
17
|
-
|
17
|
+
|
18
18
|
def authenticate(login, password)
|
19
19
|
@u = find(:first, :conditions => ["#{Merb::Authentication::Strategies::Basic::Base.login_param} = ?", login])
|
20
20
|
@u && @u.authenticated?(password) ? @u : nil
|
@@ -22,4 +22,4 @@ class Merb::Authentication
|
|
22
22
|
end # ARClassMethods
|
23
23
|
end # SaltedUser
|
24
24
|
end # Mixins
|
25
|
-
end # Merb::Authentication
|
25
|
+
end # Merb::Authentication
|
@@ -10,20 +10,20 @@ class Merb::Authentication
|
|
10
10
|
if Merb::Authentication::Mixins::SaltedUser > base
|
11
11
|
property :salt, String
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
validates_present :password, :if => proc{|m| m.password_required?}
|
15
15
|
validates_is_confirmed :password, :if => proc{|m| m.password_required?}
|
16
|
-
|
16
|
+
|
17
17
|
before :save, :encrypt_password
|
18
18
|
end # base.class_eval
|
19
|
-
|
19
|
+
|
20
20
|
end # self.extended
|
21
|
-
|
21
|
+
|
22
22
|
def authenticate(login, password)
|
23
23
|
@u = first(Merb::Authentication::Strategies::Basic::Base.login_param => login)
|
24
24
|
@u && @u.authenticated?(password) ? @u : nil
|
25
25
|
end
|
26
|
-
end # DMClassMethods
|
26
|
+
end # DMClassMethods
|
27
27
|
end # SaltedUser
|
28
28
|
end # Mixins
|
29
29
|
end # Merb::Authentication
|
@@ -10,20 +10,20 @@ class Merb::Authentication
|
|
10
10
|
if Merb::Authentication::Mixins::SaltedUser > base
|
11
11
|
field :salt, :type => String
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
validates_presence_of :password, :if => proc{|m| m.password_required?}
|
15
15
|
validates_confirmation_of :password, :if => proc{|m| m.password_required?}
|
16
|
-
|
16
|
+
|
17
17
|
before_save :encrypt_password
|
18
18
|
end # base.class_eval
|
19
|
-
|
19
|
+
|
20
20
|
end # self.extended
|
21
|
-
|
21
|
+
|
22
22
|
def authenticate(login, password)
|
23
23
|
@u = first(:conditions => { Merb::Authentication::Strategies::Basic::Base.login_param => login })
|
24
24
|
@u && @u.authenticated?(password) ? @u : nil
|
25
25
|
end
|
26
|
-
end # MongoidClassMethods
|
26
|
+
end # MongoidClassMethods
|
27
27
|
end # SaltedUser
|
28
28
|
end # Mixins
|
29
29
|
end # Merb::Authentication
|
@@ -2,10 +2,10 @@ class Merb::Authentication
|
|
2
2
|
module Mixins
|
3
3
|
module SaltedUser
|
4
4
|
module RDBClassMethods
|
5
|
-
|
5
|
+
|
6
6
|
def self.extended(base)
|
7
7
|
base.class_eval do
|
8
|
-
|
8
|
+
|
9
9
|
property :crypted_password
|
10
10
|
|
11
11
|
if Merb::Authentication::Mixins::SaltedUser > base
|
@@ -13,7 +13,7 @@ class Merb::Authentication
|
|
13
13
|
end
|
14
14
|
|
15
15
|
before_save :password_checks
|
16
|
-
|
16
|
+
|
17
17
|
def password_checks
|
18
18
|
if password_required?
|
19
19
|
return false unless !password.blank? && password == password_confirmation
|
@@ -21,16 +21,16 @@ class Merb::Authentication
|
|
21
21
|
encrypt_password
|
22
22
|
true
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def authenticate(login, password)
|
29
29
|
login_param = Merb::Authentication::Strategies::Basic::Base.login_param
|
30
30
|
@u = all.sorted_by(login_param) { |q| q.key(login) }.first
|
31
31
|
@u && @u.authenticated?(password) ? @u : nil
|
32
|
-
end
|
33
|
-
|
32
|
+
end
|
33
|
+
|
34
34
|
end # RDBClassMethods
|
35
35
|
end # SaltedUser
|
36
36
|
end # Mixins
|
@@ -41,10 +41,10 @@ class Merb::Authentication
|
|
41
41
|
validates_presence_of :password_confirmation, :if => :password_required?
|
42
42
|
validates_confirmation_of :password, :if => :password_required?
|
43
43
|
end
|
44
|
-
include Merb::Authentication::Mixins::SaltedUser::SQInstanceMethods
|
44
|
+
include Merb::Authentication::Mixins::SaltedUser::SQInstanceMethods
|
45
45
|
end
|
46
46
|
end # self.extended
|
47
|
-
|
47
|
+
|
48
48
|
def authenticate(login, password)
|
49
49
|
@u = find(Merb::Authentication::Strategies::Basic::Base.login_param => login)
|
50
50
|
@u && @u.authenticated?(password) ? @u : nil
|
@@ -53,4 +53,4 @@ class Merb::Authentication
|
|
53
53
|
|
54
54
|
end # SaltedUser
|
55
55
|
end # Mixins
|
56
|
-
end # Merb::Authentication
|
56
|
+
end # Merb::Authentication
|
@@ -4,28 +4,28 @@ class Merb::Authentication
|
|
4
4
|
# an @authenticate@ method on your user class. This should take two parameters
|
5
5
|
# login, and password. It should return nil or the user object.
|
6
6
|
module Basic
|
7
|
-
|
7
|
+
|
8
8
|
class Base < Merb::Authentication::Strategy
|
9
9
|
abstract!
|
10
|
-
|
10
|
+
|
11
11
|
# Overwrite this method to customize the field
|
12
12
|
def self.password_param
|
13
13
|
(Merb::Plugins.config[:"merb-auth"][:password_param] || :password).to_s.to_sym
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Overwrite this method to customize the field
|
17
17
|
def self.login_param
|
18
18
|
(Merb::Plugins.config[:"merb-auth"][:login_param] || :login).to_s.to_sym
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def password_param
|
22
22
|
@password_param ||= Base.password_param
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def login_param
|
26
26
|
@login_param ||= Base.login_param
|
27
27
|
end
|
28
|
-
end # Base
|
28
|
+
end # Base
|
29
29
|
end # Password
|
30
30
|
end # Strategies
|
31
31
|
end # Merb::Authentication
|
@@ -11,11 +11,11 @@ class Merb::Authentication
|
|
11
11
|
module Strategies
|
12
12
|
module Basic
|
13
13
|
class BasicAuth < Base
|
14
|
-
|
14
|
+
|
15
15
|
def run!
|
16
16
|
if basic_authentication?
|
17
17
|
basic_authentication do |login, password|
|
18
|
-
user = user_class.authenticate(login, password)
|
18
|
+
user = user_class.authenticate(login, password)
|
19
19
|
unless user
|
20
20
|
request_basic_auth!
|
21
21
|
end
|
@@ -23,29 +23,29 @@ class Merb::Authentication
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def self.realm
|
28
28
|
@realm ||= "Application"
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
cattr_writer :realm
|
32
32
|
def realm
|
33
33
|
@realm ||= self.class.realm
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
cattr_accessor :failure_message
|
37
37
|
@@failure_message = "Login Required"
|
38
|
-
|
38
|
+
|
39
39
|
private
|
40
40
|
def initialize(request, params)
|
41
41
|
super
|
42
42
|
@auth = Rack::Auth::Basic::Request.new(request.env)
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def basic_authentication?
|
46
46
|
@auth.provided? and @auth.basic?
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def username
|
50
50
|
basic_authentication? ? @auth.credentials.first : nil
|
51
51
|
end
|
@@ -53,14 +53,14 @@ class Merb::Authentication
|
|
53
53
|
def password
|
54
54
|
basic_authentication? ? @auth.credentials.last : nil
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
def request_basic_auth!
|
58
58
|
self.status = Merb::Controller::Unauthorized.status
|
59
59
|
self.headers['WWW-Authenticate'] = 'Basic realm="%s"' % realm
|
60
60
|
self.body = self.class.failure_message
|
61
61
|
halt!
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
def basic_authentication(realm = nil, &authenticator)
|
65
65
|
self.realm = realm if realm
|
66
66
|
if basic_authentication?
|
@@ -69,8 +69,8 @@ class Merb::Authentication
|
|
69
69
|
false
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
73
|
-
|
72
|
+
|
73
|
+
|
74
74
|
end # BasicAuth
|
75
75
|
end # Password
|
76
76
|
end # Strategies
|
@@ -1,6 +1,6 @@
|
|
1
|
-
# The openid strategy attempts to login users based on the OpenID protocol
|
1
|
+
# The openid strategy attempts to login users based on the OpenID protocol
|
2
2
|
# http://openid.net/
|
3
|
-
#
|
3
|
+
#
|
4
4
|
# Overwrite the on_sucess!, on_failure!, on_setup_needed!, and on_cancel! to customize events.
|
5
5
|
#
|
6
6
|
# Overwite the required_reg_fields method to require different sreg fields. Default is email and nickname
|
@@ -58,24 +58,24 @@ class Merb::Authentication
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end # run!
|
61
|
-
|
62
|
-
|
61
|
+
|
62
|
+
|
63
63
|
# Overwrite this to add extra options to the OpenID request before it is made.
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# @example request.return_to_args["remember_me"] = 1 # remember_me=1 is added when returning from the OpenID provider.
|
66
|
-
#
|
66
|
+
#
|
67
67
|
# @api overwritable
|
68
68
|
def customize_openid_request!(openid_request)
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# Used to define the callback url for the openid provider. By default it
|
72
72
|
# is set to the named :openid route.
|
73
|
-
#
|
73
|
+
#
|
74
74
|
# @api overwritable
|
75
75
|
def openid_callback_url
|
76
76
|
"#{request.protocol}://#{request.host}#{Merb::Router.url(:openid)}"
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
# Overwrite the on_success! method with the required behavior for successful logins
|
80
80
|
#
|
81
81
|
# @api overwritable
|
@@ -90,7 +90,7 @@ class Merb::Authentication
|
|
90
90
|
redirect!(Merb::Router.url(:signup))
|
91
91
|
end
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
# Overwrite the on_failure! method with the required behavior for failed logins
|
95
95
|
#
|
96
96
|
# @api overwritable
|
@@ -99,7 +99,7 @@ class Merb::Authentication
|
|
99
99
|
session.authentication.errors.add(:openid, 'OpenID verification failed, maybe the provider is down? Or the session timed out')
|
100
100
|
nil
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
#
|
104
104
|
# @api overwritable
|
105
105
|
def on_setup_needed!(response)
|
@@ -107,7 +107,7 @@ class Merb::Authentication
|
|
107
107
|
request.session.authentication.errors.add(:openid, 'OpenID does not seem to be configured correctly')
|
108
108
|
nil
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
#
|
112
112
|
# @api overwritable
|
113
113
|
def on_cancel!(response)
|
@@ -115,38 +115,38 @@ class Merb::Authentication
|
|
115
115
|
request.session.authentication.errors.add(:openid, 'OpenID rejected our request')
|
116
116
|
nil
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
#
|
120
120
|
# @api overwritable
|
121
121
|
def required_reg_fields
|
122
122
|
['nickname', 'email']
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
#
|
126
126
|
# @api overwritable
|
127
127
|
def optional_reg_fields
|
128
128
|
['fullname']
|
129
129
|
end
|
130
|
-
|
130
|
+
|
131
131
|
# Overwrite this to support an ORM other than DataMapper
|
132
132
|
#
|
133
133
|
# @api overwritable
|
134
134
|
def find_user_by_identity_url(url)
|
135
135
|
user_class.first(:identity_url => url)
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
# Overwrite this method to set your store
|
139
139
|
#
|
140
140
|
# @api overwritable
|
141
141
|
def openid_store
|
142
142
|
::OpenID::Store::Filesystem.new("#{Merb.root}/tmp/openid")
|
143
143
|
end
|
144
|
-
|
144
|
+
|
145
145
|
private
|
146
146
|
def consumer
|
147
147
|
@consumer ||= ::OpenID::Consumer.new(request.session, openid_store)
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
end # OpenID
|
151
151
|
end # Basic
|
152
152
|
end # Strategies
|
@@ -3,7 +3,7 @@ require 'merb-auth-more/strategies/abstract_password'
|
|
3
3
|
# This strategy uses a login and password parameter.
|
4
4
|
#
|
5
5
|
# Overwrite the :password_param, and :login_param
|
6
|
-
# to return the name of the field (on the form) that you're using the
|
6
|
+
# to return the name of the field (on the form) that you're using the
|
7
7
|
# login with. These can be strings or symbols
|
8
8
|
#
|
9
9
|
# == Required
|
@@ -15,7 +15,7 @@ class Merb::Authentication
|
|
15
15
|
module Strategies
|
16
16
|
module Basic
|
17
17
|
class Form < Base
|
18
|
-
|
18
|
+
|
19
19
|
def run!
|
20
20
|
if (login = request.params[login_param]) && (password = request.params[password_param])
|
21
21
|
user = user_class.authenticate(login, password)
|
@@ -27,11 +27,11 @@ class Merb::Authentication
|
|
27
27
|
user
|
28
28
|
end
|
29
29
|
end # run!
|
30
|
-
|
30
|
+
|
31
31
|
def strategy_error_message
|
32
32
|
"#{login_param.to_s.capitalize} or #{password_param.to_s.capitalize} were incorrect"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end # Form
|
36
36
|
end # Password
|
37
37
|
end # Strategies
|
@@ -6,16 +6,16 @@ require 'merb-auth-more/mixins/salted_user'
|
|
6
6
|
describe "A DataMapper Salted User" do
|
7
7
|
|
8
8
|
include UserHelper
|
9
|
-
|
9
|
+
|
10
10
|
before(:all) do
|
11
11
|
|
12
12
|
DataMapper.setup(:default, "sqlite3::memory:")
|
13
|
-
|
13
|
+
|
14
14
|
class DataMapperSaltedUser
|
15
15
|
|
16
16
|
include DataMapper::Resource
|
17
17
|
include Merb::Authentication::Mixins::SaltedUser
|
18
|
-
|
18
|
+
|
19
19
|
property :id, Serial
|
20
20
|
property :email, String
|
21
21
|
property :login, String
|
@@ -40,7 +40,7 @@ describe "every call to redirect_back", :shared => true do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
describe "redirect_back" do
|
43
|
-
|
43
|
+
|
44
44
|
before(:all) do
|
45
45
|
Merb::Config[:exception_details] = true
|
46
46
|
clear_strategies!
|
@@ -52,12 +52,12 @@ describe "redirect_back" do
|
|
52
52
|
match("/").to(:controller => "my_controller")
|
53
53
|
match("/logout", :method => :delete).to(:controller => "sessions", :action => "destroy")
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
class Merb::Authentication
|
57
57
|
def store_user(user); user; end
|
58
58
|
def fetch_user(session_info); session_info; end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# class MyStrategy < Merb::Authentication::Strategy; def run!; request.env["USER"]; end; end
|
62
62
|
class MyStrategy < Merb::Authentication::Strategy
|
63
63
|
def run!
|
@@ -65,25 +65,25 @@ describe "redirect_back" do
|
|
65
65
|
params[:pass_auth]
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
class Application < Merb::Controller; end
|
70
|
-
|
70
|
+
|
71
71
|
class Exceptions < Merb::Controller
|
72
72
|
include Merb::Authentication::Mixins::RedirectBack
|
73
|
-
|
73
|
+
|
74
74
|
def unauthenticated; end
|
75
75
|
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
class Sessions < Merb::Controller
|
79
79
|
before :ensure_authenticated
|
80
80
|
def update
|
81
81
|
redirect_back_or "/", :ignore => [url(:login)]
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
def destroy
|
85
85
|
session.abandon!
|
86
|
-
end
|
86
|
+
end
|
87
87
|
end
|
88
88
|
|
89
89
|
class MyController < Application
|
@@ -93,8 +93,8 @@ describe "redirect_back" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
end
|
97
|
-
|
96
|
+
end
|
97
|
+
|
98
98
|
def login
|
99
99
|
request("/login", :method => "put", :params => {:pass_auth => true})
|
100
100
|
end
|
@@ -114,5 +114,5 @@ describe "redirect_back" do
|
|
114
114
|
end
|
115
115
|
it_should_behave_like 'every call to redirect_back'
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
end
|
data/spec/shared_user_spec.rb
CHANGED
@@ -88,7 +88,7 @@ describe 'every salted user', :shared => true do
|
|
88
88
|
it "should set the salt" do
|
89
89
|
@new_user.salt.should be_nil
|
90
90
|
@new_user.send(:encrypt_password)
|
91
|
-
@new_user.salt.should_not be_nil
|
91
|
+
@new_user.salt.should_not be_nil
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should set the salt even when user is not new record but salt is blank" do
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb-auth-more
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Daniel Neighman
|
@@ -14,30 +15,34 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-15 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: merb-auth-core
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ~>
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 1
|
30
|
-
-
|
31
|
-
version: 1.1.
|
33
|
+
- 1
|
34
|
+
version: 1.1.1
|
32
35
|
type: :runtime
|
33
36
|
version_requirements: *id001
|
34
37
|
- !ruby/object:Gem::Dependency
|
35
38
|
name: rspec
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 13
|
41
46
|
segments:
|
42
47
|
- 1
|
43
48
|
- 2
|
@@ -93,23 +98,27 @@ rdoc_options:
|
|
93
98
|
require_paths:
|
94
99
|
- lib
|
95
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
96
102
|
requirements:
|
97
103
|
- - ">="
|
98
104
|
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
99
106
|
segments:
|
100
107
|
- 0
|
101
108
|
version: "0"
|
102
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
103
111
|
requirements:
|
104
112
|
- - ">="
|
105
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
106
115
|
segments:
|
107
116
|
- 0
|
108
117
|
version: "0"
|
109
118
|
requirements: []
|
110
119
|
|
111
120
|
rubyforge_project:
|
112
|
-
rubygems_version: 1.3.
|
121
|
+
rubygems_version: 1.3.7
|
113
122
|
signing_key:
|
114
123
|
specification_version: 3
|
115
124
|
summary: Additional resources for use with the merb-auth-core authentication framework.
|