sorcery 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- data/README.rdoc +44 -6
- data/VERSION +1 -1
- data/lib/generators/sorcery_migration/templates/{oauth.rb → external.rb} +1 -1
- data/lib/sorcery/controller/submodules/email.rb +44 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +35 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +26 -0
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/facebook.rb +24 -6
- data/lib/sorcery/controller/submodules/{oauth → external}/providers/twitter.rb +31 -6
- data/lib/sorcery/controller/submodules/external.rb +83 -0
- data/lib/sorcery/controller.rb +5 -3
- data/lib/sorcery/model/submodules/{oauth.rb → external.rb} +3 -3
- data/lib/sorcery/model.rb +9 -6
- data/lib/sorcery.rb +9 -7
- data/sorcery.gemspec +14 -12
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +2 -2
- data/spec/rails3/app_root/Gemfile +1 -1
- data/spec/rails3/app_root/Gemfile.lock +2 -2
- data/spec/rails3/app_root/app/controllers/application_controller.rb +11 -11
- data/spec/rails3/app_root/db/migrate/{oauth → external}/20101224223628_create_authentications.rb +0 -0
- data/spec/rails3/app_root/spec/controller_oauth2_spec.rb +13 -13
- data/spec/rails3/app_root/spec/controller_oauth_spec.rb +12 -12
- data/spec/rails3/app_root/spec/user_oauth_spec.rb +4 -4
- data/spec/rails3/app_root/spec/user_spec.rb +2 -2
- data/spec/sinatra/Gemfile +1 -1
- data/spec/sinatra/Gemfile.lock +2 -2
- data/spec/sinatra/db/migrate/{oauth → external}/20101224223628_create_authentications.rb +0 -0
- data/spec/sinatra/myapp.rb +11 -11
- data/spec/sinatra/spec/controller_oauth2_spec.rb +13 -13
- data/spec/sinatra/spec/controller_oauth_spec.rb +12 -12
- data/spec/sinatra/spec/user_oauth_spec.rb +4 -4
- data/spec/sinatra/spec/user_spec.rb +2 -2
- metadata +14 -12
- data/lib/sorcery/controller/submodules/oauth/oauth1.rb +0 -33
- data/lib/sorcery/controller/submodules/oauth/oauth2.rb +0 -24
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ Crypto code taken almost unchanged from Authlogic.
|
|
6
6
|
OAuth code inspired by OmniAuth and Ryan Bates's railscasts about it.
|
7
7
|
|
8
8
|
|
9
|
-
==
|
9
|
+
== Philosophy
|
10
10
|
|
11
11
|
|
12
12
|
Sorcery is a stripped-down, bare-bones authentication library, with which you can write your own authentication flow.
|
@@ -28,7 +28,7 @@ Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
|
|
28
28
|
|
29
29
|
Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
|
30
30
|
|
31
|
-
Documentation: http://rubydoc.info/gems/sorcery/0.3.
|
31
|
+
Documentation: http://rubydoc.info/gems/sorcery/0.3.1/frames
|
32
32
|
|
33
33
|
Check out the tutorials in the github wiki!
|
34
34
|
|
@@ -88,10 +88,44 @@ To generate migrations for both the core AND 'remember_me' submodule:
|
|
88
88
|
These migrations use the default fields. You can choose to use these migrations or make your own tables and fields. Sorcery tries not to impose a database structure and naming scheme on your application.
|
89
89
|
|
90
90
|
|
91
|
-
==
|
91
|
+
== API Summary
|
92
92
|
|
93
|
+
Below is a summary of the library methods. Most method names are self explaining and the rest are commented:
|
93
94
|
|
94
|
-
|
95
|
+
# core
|
96
|
+
require_login # this is a before filter
|
97
|
+
login(username,password,remember_me = false)
|
98
|
+
logout
|
99
|
+
logged_in?
|
100
|
+
current_user
|
101
|
+
redirect_back_or_to # used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
|
102
|
+
@user.external? # external users, such as facebook/twitter etc.
|
103
|
+
|
104
|
+
# activity logging
|
105
|
+
current_users
|
106
|
+
|
107
|
+
# http basic auth
|
108
|
+
require_login_from_http_basic # this is a before filter
|
109
|
+
|
110
|
+
# external
|
111
|
+
login_at(provider) # sends the user to an external service (twitter etc.) to authenticate.
|
112
|
+
login_from(provider) # tries to login from the external provider's callback.
|
113
|
+
create_from(provider) # create the user in the local app db.
|
114
|
+
|
115
|
+
# remember me
|
116
|
+
remember_me!
|
117
|
+
forget_me!
|
118
|
+
|
119
|
+
# reset password
|
120
|
+
User.load_from_reset_password_token(token)
|
121
|
+
@user.deliver_reset_password_instructions!
|
122
|
+
@user.reset_password!(params)
|
123
|
+
|
124
|
+
# user activation
|
125
|
+
User.load_from_activation_token(token)
|
126
|
+
@user.activate!
|
127
|
+
|
128
|
+
Please see the tutorials in the github wiki for detailed usage information.
|
95
129
|
|
96
130
|
|
97
131
|
== Full Features List by module:
|
@@ -137,7 +171,7 @@ Activity Logging (see lib/sorcery/model/submodules/activity_logging.rb):
|
|
137
171
|
* an easy method of collecting the list of currently logged in users.
|
138
172
|
* configurable timeout by which to decide whether to include a user in the list of logged in users.
|
139
173
|
|
140
|
-
|
174
|
+
External (see lib/sorcery/controller/submodules/external.rb):
|
141
175
|
* OAuth1 and OAuth2 support (currently twitter & facebook)
|
142
176
|
* configurable db field names and authentications table.
|
143
177
|
|
@@ -150,14 +184,18 @@ I've got many plans which include (by priority):
|
|
150
184
|
* Simple auth (no user)
|
151
185
|
* Switching authentication mode at runtime (Maintenance mode)
|
152
186
|
* Mongoid support
|
153
|
-
* Configurable Auto login on registration/activation
|
154
187
|
* Other reset password strategies (security questions?)
|
155
188
|
* Other brute force protection strategies (captcha)
|
156
189
|
* Have an idea? Let me know, and it might get into the gem!
|
157
190
|
|
191
|
+
Other stuff:
|
192
|
+
* Improve documentation
|
193
|
+
* Tty to reduce the number of library methods, and find better names to some
|
194
|
+
|
158
195
|
|
159
196
|
== Contributing to sorcery
|
160
197
|
|
198
|
+
|
161
199
|
Your feedback is very welcome and will make this gem much much better for you, me and everyone else.
|
162
200
|
Besides feedback on code, features, suggestions and bug reports, you may want to actually make an impact on the code.
|
163
201
|
For this:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# module Sorcery
|
2
|
+
# module Controller
|
3
|
+
# module Submodules
|
4
|
+
# # This module allows you to authenticate to the site using a mail server.
|
5
|
+
# # Let's say your organization is called blup, and everyone has someklutz@blup.com,
|
6
|
+
# # Instead of registering a new username and password for an internal web application,
|
7
|
+
# # why not simply reuse your email credentials?
|
8
|
+
# # Of course this means that if the mail server is down, nobody can authenticate to your app.
|
9
|
+
# # I might add a fallback for that in the future.
|
10
|
+
# module Email
|
11
|
+
# def self.included(base)
|
12
|
+
# base.send(:include, InstanceMethods)
|
13
|
+
# Config.module_eval do
|
14
|
+
# class << self
|
15
|
+
# attr_reader :email_protocols # email protocols like pop3, IMAP etc.
|
16
|
+
#
|
17
|
+
# def merge_mail_defaults!
|
18
|
+
# @defaults.merge!(:@email_protocols => [])
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def email_protocols=(protocols)
|
22
|
+
# protocols.each do |protocol|
|
23
|
+
# include Protocols.const_get(protocol.to_s.split("_").map {|p| p.capitalize}.join(""))
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# merge_mail_defaults!
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# module InstanceMethods
|
32
|
+
# protected
|
33
|
+
#
|
34
|
+
# # sends user to authenticate at the provider's website.
|
35
|
+
# # after authentication the user is redirected to the callback defined in the provider config
|
36
|
+
# def login_at(protocol)
|
37
|
+
#
|
38
|
+
# end
|
39
|
+
#
|
40
|
+
# end
|
41
|
+
# end
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
# end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
module Sorcery
|
3
|
+
module Controller
|
4
|
+
module Submodules
|
5
|
+
module External
|
6
|
+
module Protocols
|
7
|
+
module Oauth1
|
8
|
+
def oauth_version
|
9
|
+
"1.0"
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_request_token(token=nil,secret=nil)
|
13
|
+
return ::OAuth::RequestToken.new(get_consumer,token,secret) if token && secret
|
14
|
+
get_consumer.get_request_token(:oauth_callback => @callback_url)
|
15
|
+
end
|
16
|
+
|
17
|
+
def authorize_url(args)
|
18
|
+
get_request_token(args[:request_token],args[:request_token_secret]).authorize_url(:oauth_callback => @callback_url)
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_access_token(args)
|
22
|
+
get_request_token(args[:request_token],args[:request_token_secret]).get_access_token(:oauth_verifier => args[:oauth_verifier])
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def get_consumer
|
28
|
+
::OAuth::Consumer.new(@key, @secret, :site => @site)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
module Sorcery
|
3
|
+
module Controller
|
4
|
+
module Submodules
|
5
|
+
module External
|
6
|
+
module Protocols
|
7
|
+
module Oauth2
|
8
|
+
def oauth_version
|
9
|
+
"2.0"
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorize_url(*args)
|
13
|
+
client = ::OAuth2::Client.new(@key, @secret, :site => @site)
|
14
|
+
client.web_server.authorize_url(:redirect_uri => @callback_url, :scope => @scope)
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_access_token(args)
|
18
|
+
client = ::OAuth2::Client.new(@key, @secret, :site => @site)
|
19
|
+
client.web_server.get_access_token(args[:code], :redirect_uri => @callback_url)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sorcery
|
2
2
|
module Controller
|
3
3
|
module Submodules
|
4
|
-
module
|
4
|
+
module External
|
5
5
|
module Providers
|
6
6
|
# This module adds support for OAuth with facebook.com.
|
7
7
|
# When included in the 'config.providers' option, it adds a new option, 'config.facebook'.
|
@@ -16,7 +16,7 @@ module Sorcery
|
|
16
16
|
base.module_eval do
|
17
17
|
class << self
|
18
18
|
attr_reader :facebook # access to facebook_client.
|
19
|
-
|
19
|
+
|
20
20
|
def merge_facebook_defaults!
|
21
21
|
@defaults.merge!(:@facebook => FacebookClient)
|
22
22
|
end
|
@@ -36,7 +36,7 @@ module Sorcery
|
|
36
36
|
:scope,
|
37
37
|
:user_info_mapping
|
38
38
|
|
39
|
-
include Oauth2
|
39
|
+
include Protocols::Oauth2
|
40
40
|
|
41
41
|
def init
|
42
42
|
@site = "https://graph.facebook.com"
|
@@ -45,13 +45,31 @@ module Sorcery
|
|
45
45
|
@user_info_mapping = {}
|
46
46
|
end
|
47
47
|
|
48
|
-
def get_user_hash
|
48
|
+
def get_user_hash
|
49
49
|
user_hash = {}
|
50
|
-
response = access_token.get(@user_info_path)
|
50
|
+
response = @access_token.get(@user_info_path)
|
51
51
|
user_hash[:user_info] = JSON.parse(response)
|
52
|
-
user_hash[:uid] = user_hash[:user_info]['id']
|
52
|
+
user_hash[:uid] = user_hash[:user_info]['id']
|
53
53
|
user_hash
|
54
54
|
end
|
55
|
+
|
56
|
+
def has_callback?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
# calculates and returns the url to which the user should be redirected,
|
61
|
+
# to get authenticated at the external provider's site.
|
62
|
+
def login_url(params,session)
|
63
|
+
self.authorize_url
|
64
|
+
end
|
65
|
+
|
66
|
+
# tries to login the user from access token
|
67
|
+
def process_callback(params,session)
|
68
|
+
args = {}
|
69
|
+
args.merge!({:code => params[:code]}) if params[:code]
|
70
|
+
@access_token = self.get_access_token(args)
|
71
|
+
end
|
72
|
+
|
55
73
|
end
|
56
74
|
init
|
57
75
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Sorcery
|
2
2
|
module Controller
|
3
3
|
module Submodules
|
4
|
-
module
|
4
|
+
module External
|
5
5
|
module Providers
|
6
6
|
# This module adds support for OAuth with Twitter.com.
|
7
7
|
# When included in the 'config.providers' option, it adds a new option, 'config.twitter'.
|
@@ -15,7 +15,10 @@ module Sorcery
|
|
15
15
|
def self.included(base)
|
16
16
|
base.module_eval do
|
17
17
|
class << self
|
18
|
-
attr_reader :twitter
|
18
|
+
attr_reader :twitter
|
19
|
+
# def twitter(&blk) # allows block syntax.
|
20
|
+
# yield @twitter
|
21
|
+
# end
|
19
22
|
|
20
23
|
def merge_twitter_defaults!
|
21
24
|
@defaults.merge!(:@twitter => TwitterClient)
|
@@ -25,7 +28,7 @@ module Sorcery
|
|
25
28
|
update!
|
26
29
|
end
|
27
30
|
end
|
28
|
-
|
31
|
+
|
29
32
|
module TwitterClient
|
30
33
|
class << self
|
31
34
|
attr_accessor :key,
|
@@ -35,7 +38,7 @@ module Sorcery
|
|
35
38
|
:user_info_path,
|
36
39
|
:user_info_mapping
|
37
40
|
|
38
|
-
include Oauth1
|
41
|
+
include Protocols::Oauth1
|
39
42
|
|
40
43
|
def init
|
41
44
|
@site = "https://api.twitter.com"
|
@@ -43,13 +46,35 @@ module Sorcery
|
|
43
46
|
@user_info_mapping = {}
|
44
47
|
end
|
45
48
|
|
46
|
-
def get_user_hash
|
49
|
+
def get_user_hash
|
47
50
|
user_hash = {}
|
48
|
-
response = access_token.get(@user_info_path)
|
51
|
+
response = @access_token.get(@user_info_path)
|
49
52
|
user_hash[:user_info] = JSON.parse(response.body)
|
50
53
|
user_hash[:uid] = user_hash[:user_info]['id']
|
51
54
|
user_hash
|
52
55
|
end
|
56
|
+
|
57
|
+
def has_callback?
|
58
|
+
true
|
59
|
+
end
|
60
|
+
|
61
|
+
# calculates and returns the url to which the user should be redirected,
|
62
|
+
# to get authenticated at the external provider's site.
|
63
|
+
def login_url(params,session)
|
64
|
+
req_token = self.get_request_token
|
65
|
+
session[:request_token] = req_token.token
|
66
|
+
session[:request_token_secret] = req_token.secret
|
67
|
+
self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
|
68
|
+
end
|
69
|
+
|
70
|
+
# tries to login the user from access token
|
71
|
+
def process_callback(params,session)
|
72
|
+
args = {}
|
73
|
+
args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
|
74
|
+
args.merge!({:code => params[:code]}) if params[:code]
|
75
|
+
@access_token = self.get_access_token(args)
|
76
|
+
end
|
77
|
+
|
53
78
|
end
|
54
79
|
init
|
55
80
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Sorcery
|
2
|
+
module Controller
|
3
|
+
module Submodules
|
4
|
+
# This submodule helps you login users from external auth providers such as Twitter.
|
5
|
+
# This is the controller part which handles the http requests and tokens passed between the app and the provider.
|
6
|
+
module External
|
7
|
+
def self.included(base)
|
8
|
+
base.send(:include, InstanceMethods)
|
9
|
+
Config.module_eval do
|
10
|
+
class << self
|
11
|
+
attr_reader :external_providers # external providers like twitter.
|
12
|
+
|
13
|
+
def merge_external_defaults!
|
14
|
+
@defaults.merge!(:@external_providers => [])
|
15
|
+
end
|
16
|
+
|
17
|
+
def external_providers=(providers)
|
18
|
+
providers.each do |provider|
|
19
|
+
include Providers.const_get(provider.to_s.split("_").map {|p| p.capitalize}.join(""))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
merge_external_defaults!
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module InstanceMethods
|
28
|
+
protected
|
29
|
+
|
30
|
+
# sends user to authenticate at the provider's website.
|
31
|
+
# after authentication the user is redirected to the callback defined in the provider config
|
32
|
+
def login_at(provider, args = {})
|
33
|
+
@provider = Config.send(provider)
|
34
|
+
if @provider.has_callback?
|
35
|
+
redirect_to @provider.login_url(params,session)
|
36
|
+
else
|
37
|
+
#@provider.login(args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# tries to login the user from provider's callback
|
42
|
+
def login_from(provider)
|
43
|
+
@provider = Config.send(provider)
|
44
|
+
@provider.process_callback(params,session)
|
45
|
+
@user_hash = @provider.get_user_hash
|
46
|
+
if user = Config.user_class.load_from_provider(provider,@user_hash[:uid])
|
47
|
+
reset_session
|
48
|
+
login_user(user)
|
49
|
+
user
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# this method automatically creates a new user from the data in the external user hash.
|
54
|
+
# The mappings from user hash fields to user db fields are set at controller config.
|
55
|
+
# If the hash field you would like to map is nested, use slashes. For example, Given a hash like:
|
56
|
+
#
|
57
|
+
# "user" => {"name"=>"moishe"}
|
58
|
+
#
|
59
|
+
# You will set the mapping:
|
60
|
+
#
|
61
|
+
# {:username => "user/name"}
|
62
|
+
#
|
63
|
+
# And this will cause 'moishe' to be set as the value of :username field.
|
64
|
+
def create_from(provider)
|
65
|
+
provider = provider.to_sym
|
66
|
+
@provider = Config.send(provider)
|
67
|
+
@user_hash = @provider.get_user_hash
|
68
|
+
config = Config.user_class.sorcery_config
|
69
|
+
attrs = {}
|
70
|
+
@provider.user_info_mapping.each do |k,v|
|
71
|
+
(varr = v.split("/")).size > 1 ? attrs.merge!(k => varr.inject(@user_hash[:user_info]) {|hsh,v| hsh[v] }) : attrs.merge!(k => @user_hash[:user_info][v])
|
72
|
+
end
|
73
|
+
Config.user_class.transaction do
|
74
|
+
@user = Config.user_class.create!(attrs)
|
75
|
+
Config.user_class.sorcery_config.authentications_class.create!({config.authentications_user_id_attribute_name => @user.id, config.provider_attribute_name => provider, config.provider_uid_attribute_name => @user_hash[:uid]})
|
76
|
+
end
|
77
|
+
@user
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/sorcery/controller.rb
CHANGED
@@ -5,7 +5,7 @@ module Sorcery
|
|
5
5
|
extend ClassMethods
|
6
6
|
include InstanceMethods
|
7
7
|
Config.submodules.each do |mod|
|
8
|
-
begin
|
8
|
+
begin
|
9
9
|
include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
|
10
10
|
rescue NameError
|
11
11
|
# don't stop on a missing submodule.
|
@@ -73,12 +73,14 @@ module Sorcery
|
|
73
73
|
@current_user ||= login_from_session || login_from_other_sources unless @current_user == false
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
# used when a user tries to access a page while logged out, is asked to login, and we want to return him back to the page he originally wanted.
|
77
|
+
def redirect_back_or_to(url, flash_hash = {})
|
77
78
|
redirect_to(session[:return_to_url] || url, :flash => flash_hash)
|
78
79
|
end
|
79
80
|
|
80
81
|
# The default action for denying non-authenticated users.
|
81
|
-
# You can override this method in your controllers
|
82
|
+
# You can override this method in your controllers,
|
83
|
+
# or provide a different method in the configuration.
|
82
84
|
def not_authenticated
|
83
85
|
redirect_to root_path
|
84
86
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Sorcery
|
2
2
|
module Model
|
3
3
|
module Submodules
|
4
|
-
# This submodule helps you login users from
|
4
|
+
# This submodule helps you login users from external providers such as Twitter.
|
5
5
|
# This is the model part which handles finding the user using access tokens.
|
6
|
-
# For the controller options see Sorcery::Controller::
|
6
|
+
# For the controller options see Sorcery::Controller::External.
|
7
7
|
#
|
8
8
|
# Socery assumes (read: requires) you will create external users in the same table where you keep your regular users,
|
9
9
|
# but that you will have a separate table for keeping their external authentication data,
|
@@ -11,7 +11,7 @@ module Sorcery
|
|
11
11
|
#
|
12
12
|
# External users will have a null crypted_password field, since we do not hold their password.
|
13
13
|
# They will not be sent activation emails on creation.
|
14
|
-
module
|
14
|
+
module External
|
15
15
|
def self.included(base)
|
16
16
|
base.sorcery_config.class_eval do
|
17
17
|
attr_accessor :authentications_class,
|
data/lib/sorcery/model.rb
CHANGED
@@ -56,12 +56,6 @@ module Sorcery
|
|
56
56
|
user if user && @sorcery_config.before_authenticate.all? {|c| user.send(c)} && credentials_match?(user.send(@sorcery_config.crypted_password_attribute_name),credentials[1],_salt)
|
57
57
|
end
|
58
58
|
|
59
|
-
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
60
|
-
def credentials_match?(crypted, *tokens)
|
61
|
-
return crypted == tokens.join if @sorcery_config.encryption_provider.nil?
|
62
|
-
@sorcery_config.encryption_provider.matches?(crypted, *tokens)
|
63
|
-
end
|
64
|
-
|
65
59
|
# encrypt tokens using current encryption_provider.
|
66
60
|
def encrypt(*tokens)
|
67
61
|
return tokens.first if @sorcery_config.encryption_provider.nil?
|
@@ -71,6 +65,15 @@ module Sorcery
|
|
71
65
|
CryptoProviders::AES256.key = @sorcery_config.encryption_key if @sorcery_config.encryption_algorithm == :aes256
|
72
66
|
@sorcery_config.encryption_provider.encrypt(*tokens)
|
73
67
|
end
|
68
|
+
|
69
|
+
protected
|
70
|
+
|
71
|
+
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
72
|
+
def credentials_match?(crypted, *tokens)
|
73
|
+
return crypted == tokens.join if @sorcery_config.encryption_provider.nil?
|
74
|
+
@sorcery_config.encryption_provider.matches?(crypted, *tokens)
|
75
|
+
end
|
76
|
+
|
74
77
|
end
|
75
78
|
|
76
79
|
module InstanceMethods
|
data/lib/sorcery.rb
CHANGED
@@ -8,7 +8,7 @@ module Sorcery
|
|
8
8
|
autoload :RememberMe, 'sorcery/model/submodules/remember_me'
|
9
9
|
autoload :ActivityLogging, 'sorcery/model/submodules/activity_logging'
|
10
10
|
autoload :BruteForceProtection, 'sorcery/model/submodules/brute_force_protection'
|
11
|
-
autoload :
|
11
|
+
autoload :External, 'sorcery/model/submodules/external'
|
12
12
|
end
|
13
13
|
end
|
14
14
|
autoload :Controller, 'sorcery/controller'
|
@@ -19,13 +19,15 @@ module Sorcery
|
|
19
19
|
autoload :BruteForceProtection, 'sorcery/controller/submodules/brute_force_protection'
|
20
20
|
autoload :HttpBasicAuth, 'sorcery/controller/submodules/http_basic_auth'
|
21
21
|
autoload :ActivityLogging, 'sorcery/controller/submodules/activity_logging'
|
22
|
-
autoload :
|
23
|
-
module
|
24
|
-
|
25
|
-
|
22
|
+
autoload :External, 'sorcery/controller/submodules/external'
|
23
|
+
module External
|
24
|
+
module Protocols
|
25
|
+
autoload :Oauth1, 'sorcery/controller/submodules/external/protocols/oauth1'
|
26
|
+
autoload :Oauth2, 'sorcery/controller/submodules/external/protocols/oauth2'
|
27
|
+
end
|
26
28
|
module Providers
|
27
|
-
autoload :Twitter, 'sorcery/controller/submodules/
|
28
|
-
autoload :Facebook, 'sorcery/controller/submodules/
|
29
|
+
autoload :Twitter, 'sorcery/controller/submodules/external/providers/twitter'
|
30
|
+
autoload :Facebook, 'sorcery/controller/submodules/external/providers/facebook'
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
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.3.
|
8
|
+
s.version = "0.3.1"
|
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-04-
|
12
|
+
s.date = %q{2011-04-17}
|
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 = [
|
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/generators/sorcery_migration/templates/activity_logging.rb",
|
30
30
|
"lib/generators/sorcery_migration/templates/brute_force_protection.rb",
|
31
31
|
"lib/generators/sorcery_migration/templates/core.rb",
|
32
|
-
"lib/generators/sorcery_migration/templates/
|
32
|
+
"lib/generators/sorcery_migration/templates/external.rb",
|
33
33
|
"lib/generators/sorcery_migration/templates/remember_me.rb",
|
34
34
|
"lib/generators/sorcery_migration/templates/reset_password.rb",
|
35
35
|
"lib/generators/sorcery_migration/templates/user_activation.rb",
|
@@ -38,12 +38,14 @@ Gem::Specification.new do |s|
|
|
38
38
|
"lib/sorcery/controller/adapters/sinatra.rb",
|
39
39
|
"lib/sorcery/controller/submodules/activity_logging.rb",
|
40
40
|
"lib/sorcery/controller/submodules/brute_force_protection.rb",
|
41
|
+
"lib/sorcery/controller/submodules/email.rb",
|
42
|
+
"lib/sorcery/controller/submodules/external.rb",
|
43
|
+
"lib/sorcery/controller/submodules/external/protocols/oauth1.rb",
|
44
|
+
"lib/sorcery/controller/submodules/external/protocols/oauth2.rb",
|
45
|
+
"lib/sorcery/controller/submodules/external/providers/facebook.rb",
|
46
|
+
"lib/sorcery/controller/submodules/external/providers/twitter.rb",
|
41
47
|
"lib/sorcery/controller/submodules/http_basic_auth.rb",
|
42
48
|
"lib/sorcery/controller/submodules/oauth.rb",
|
43
|
-
"lib/sorcery/controller/submodules/oauth/oauth1.rb",
|
44
|
-
"lib/sorcery/controller/submodules/oauth/oauth2.rb",
|
45
|
-
"lib/sorcery/controller/submodules/oauth/providers/facebook.rb",
|
46
|
-
"lib/sorcery/controller/submodules/oauth/providers/twitter.rb",
|
47
49
|
"lib/sorcery/controller/submodules/remember_me.rb",
|
48
50
|
"lib/sorcery/controller/submodules/session_timeout.rb",
|
49
51
|
"lib/sorcery/crypto_providers/aes256.rb",
|
@@ -56,7 +58,7 @@ Gem::Specification.new do |s|
|
|
56
58
|
"lib/sorcery/model.rb",
|
57
59
|
"lib/sorcery/model/submodules/activity_logging.rb",
|
58
60
|
"lib/sorcery/model/submodules/brute_force_protection.rb",
|
59
|
-
"lib/sorcery/model/submodules/
|
61
|
+
"lib/sorcery/model/submodules/external.rb",
|
60
62
|
"lib/sorcery/model/submodules/remember_me.rb",
|
61
63
|
"lib/sorcery/model/submodules/reset_password.rb",
|
62
64
|
"lib/sorcery/model/submodules/user_activation.rb",
|
@@ -109,7 +111,7 @@ Gem::Specification.new do |s|
|
|
109
111
|
"spec/rails3/app_root/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
110
112
|
"spec/rails3/app_root/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
111
113
|
"spec/rails3/app_root/db/migrate/core/20101224223620_create_users.rb",
|
112
|
-
"spec/rails3/app_root/db/migrate/
|
114
|
+
"spec/rails3/app_root/db/migrate/external/20101224223628_create_authentications.rb",
|
113
115
|
"spec/rails3/app_root/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
114
116
|
"spec/rails3/app_root/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
115
117
|
"spec/rails3/app_root/db/schema.rb",
|
@@ -156,7 +158,7 @@ Gem::Specification.new do |s|
|
|
156
158
|
"spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
157
159
|
"spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
158
160
|
"spec/sinatra/db/migrate/core/20101224223620_create_users.rb",
|
159
|
-
"spec/sinatra/db/migrate/
|
161
|
+
"spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb",
|
160
162
|
"spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
161
163
|
"spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
162
164
|
"spec/sinatra/filters.rb",
|
@@ -213,7 +215,7 @@ Gem::Specification.new do |s|
|
|
213
215
|
"spec/rails3/app_root/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
214
216
|
"spec/rails3/app_root/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
215
217
|
"spec/rails3/app_root/db/migrate/core/20101224223620_create_users.rb",
|
216
|
-
"spec/rails3/app_root/db/migrate/
|
218
|
+
"spec/rails3/app_root/db/migrate/external/20101224223628_create_authentications.rb",
|
217
219
|
"spec/rails3/app_root/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
218
220
|
"spec/rails3/app_root/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
219
221
|
"spec/rails3/app_root/db/schema.rb",
|
@@ -240,7 +242,7 @@ Gem::Specification.new do |s|
|
|
240
242
|
"spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb",
|
241
243
|
"spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb",
|
242
244
|
"spec/sinatra/db/migrate/core/20101224223620_create_users.rb",
|
243
|
-
"spec/sinatra/db/migrate/
|
245
|
+
"spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb",
|
244
246
|
"spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb",
|
245
247
|
"spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb",
|
246
248
|
"spec/sinatra/filters.rb",
|
data/spec/Gemfile
CHANGED
data/spec/Gemfile.lock
CHANGED