sorcery 0.5.30 → 0.6.0
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 +9 -1
- data/VERSION +1 -1
- data/lib/sorcery/controller.rb +7 -6
- data/lib/sorcery/controller/submodules/activity_logging.rb +1 -1
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +2 -2
- data/lib/sorcery/controller/submodules/external.rb +11 -6
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
- data/lib/sorcery/controller/submodules/remember_me.rb +1 -1
- data/lib/sorcery/initializers/initializer.rb +1 -1
- data/lib/sorcery/model.rb +30 -11
- data/lib/sorcery/model/adapters/mongoid.rb +2 -2
- data/lib/sorcery/test_helpers/internal/rails.rb +1 -1
- data/lib/sorcery/test_helpers/internal/sinatra.rb +1 -1
- data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +1 -1
- data/sorcery.gemspec +6 -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_mongoid/Gemfile.lock +1 -1
- 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_oauth_shared_examples.rb +1 -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 +6 -2
data/README.rdoc
CHANGED
@@ -29,7 +29,7 @@ Example Rails 3 app using sorcery: https://github.com/NoamB/sorcery-example-app
|
|
29
29
|
|
30
30
|
Example Sinatra app using sorcery: https://github.com/NoamB/sorcery-example-app-sinatra
|
31
31
|
|
32
|
-
Documentation: http://rubydoc.info/gems/sorcery/0.
|
32
|
+
Documentation: http://rubydoc.info/gems/sorcery/0.6.0/frames
|
33
33
|
|
34
34
|
Check out the tutorials in the github wiki!
|
35
35
|
|
@@ -224,6 +224,14 @@ The patch version changes are backward compatible.
|
|
224
224
|
In short, an app that works with x.3.1 should be able to upgrade to x.3.2 with no code changes.
|
225
225
|
The same cannot be said about upgrading to x.4.0 and above, however.
|
226
226
|
|
227
|
+
== Upgrading
|
228
|
+
|
229
|
+
Important notes while upgrading:
|
230
|
+
|
231
|
+
* If upgrading from <= v0.5.1 to >= v0.5.2 you need to explicitly set your user_class model in the initializer file.
|
232
|
+
|
233
|
+
# This line must come after the 'user config' block.
|
234
|
+
config.user_class = User
|
227
235
|
|
228
236
|
== Contributing to sorcery
|
229
237
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/sorcery/controller.rb
CHANGED
@@ -29,7 +29,7 @@ module Sorcery
|
|
29
29
|
# Takes credentials and returns a user on successful authentication.
|
30
30
|
# Runs hooks after login or failed login.
|
31
31
|
def login(*credentials)
|
32
|
-
user =
|
32
|
+
user = user_class.authenticate(*credentials)
|
33
33
|
if user
|
34
34
|
return_to_url = session[:return_to_url]
|
35
35
|
reset_session # protect from session fixation attacks
|
@@ -91,7 +91,7 @@ module Sorcery
|
|
91
91
|
end
|
92
92
|
|
93
93
|
def login_from_session
|
94
|
-
@current_user = (
|
94
|
+
@current_user = (user_class.find_by_id(session[:user_id]) if session[:user_id]) || false
|
95
95
|
end
|
96
96
|
|
97
97
|
def after_login!(user, credentials)
|
@@ -110,14 +110,15 @@ module Sorcery
|
|
110
110
|
Config.after_logout.each {|c| self.send(c)}
|
111
111
|
end
|
112
112
|
|
113
|
+
def user_class
|
114
|
+
@user_class ||= Config.user_class.to_s.constantize
|
115
|
+
end
|
113
116
|
end
|
114
117
|
|
115
118
|
module Config
|
116
119
|
class << self
|
117
120
|
attr_accessor :submodules,
|
118
|
-
|
119
121
|
:user_class, # what class to use as the user class.
|
120
|
-
|
121
122
|
:not_authenticated_action, # what controller action to call for non-authenticated users.
|
122
123
|
|
123
124
|
:save_return_to_url, # when a non logged in user tries to enter a page that requires
|
@@ -128,8 +129,8 @@ module Sorcery
|
|
128
129
|
:after_login,
|
129
130
|
:after_failed_login,
|
130
131
|
:before_logout,
|
131
|
-
:after_logout
|
132
|
-
|
132
|
+
:after_logout
|
133
|
+
|
133
134
|
def init!
|
134
135
|
@defaults = {
|
135
136
|
:@user_class => nil,
|
@@ -22,7 +22,7 @@ module Sorcery
|
|
22
22
|
module InstanceMethods
|
23
23
|
# Returns an array of the active users.
|
24
24
|
def current_users
|
25
|
-
|
25
|
+
user_class.current_users
|
26
26
|
# A possible patch here:
|
27
27
|
# we'll add the current_user to the users list if he's not in it
|
28
28
|
# (can happen when he was inactive for more than activity timeout):
|
@@ -22,14 +22,14 @@ module Sorcery
|
|
22
22
|
# Increments the failed logins counter on every failed login.
|
23
23
|
# Runs as a hook after a failed login.
|
24
24
|
def update_failed_logins_count!(credentials)
|
25
|
-
user =
|
25
|
+
user = user_class.find_by_credentials(credentials)
|
26
26
|
user.register_failed_login! if user
|
27
27
|
end
|
28
28
|
|
29
29
|
# Resets the failed logins counter.
|
30
30
|
# Runs as a hook after a successful login.
|
31
31
|
def reset_failed_logins_count!(user, credentials)
|
32
|
-
user.update_attributes!(
|
32
|
+
user.update_attributes!(user_class.sorcery_config.failed_logins_count_attribute_name => 0)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -43,7 +43,7 @@ module Sorcery
|
|
43
43
|
@provider = Config.send(provider)
|
44
44
|
@provider.process_callback(params,session)
|
45
45
|
@user_hash = @provider.get_user_hash
|
46
|
-
if user =
|
46
|
+
if user = user_class.load_from_provider(provider,@user_hash[:uid])
|
47
47
|
reset_session
|
48
48
|
login_user(user)
|
49
49
|
user
|
@@ -65,14 +65,19 @@ module Sorcery
|
|
65
65
|
provider = provider.to_sym
|
66
66
|
@provider = Config.send(provider)
|
67
67
|
@user_hash = @provider.get_user_hash
|
68
|
-
config =
|
68
|
+
config = user_class.sorcery_config
|
69
69
|
attrs = {}
|
70
70
|
@provider.user_info_mapping.each do |k,v|
|
71
|
-
(varr = v.split("/")).size > 1
|
71
|
+
if (varr = v.split("/")).size > 1
|
72
|
+
attribute_value = varr.inject(@user_hash[:user_info]) {|hsh,v| hsh[v] } rescue nil
|
73
|
+
attribute_value.nil? ? attrs : attrs.merge!(k => attribute_value)
|
74
|
+
else
|
75
|
+
attrs.merge!(k => @user_hash[:user_info][v])
|
76
|
+
end
|
72
77
|
end
|
73
|
-
|
74
|
-
@user =
|
75
|
-
|
78
|
+
user_class.transaction do
|
79
|
+
@user = user_class.create!(attrs)
|
80
|
+
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
81
|
end
|
77
82
|
@user
|
78
83
|
end
|
@@ -45,7 +45,7 @@ module Sorcery
|
|
45
45
|
# given to main controller module as a login source callback
|
46
46
|
def login_from_basic_auth
|
47
47
|
authenticate_with_http_basic do |username, password|
|
48
|
-
@current_user = (
|
48
|
+
@current_user = (user_class.authenticate(username, password) if session[:http_authentication_used]) || false
|
49
49
|
login_user(@current_user) if @current_user
|
50
50
|
@current_user
|
51
51
|
end
|
@@ -38,7 +38,7 @@ module Sorcery
|
|
38
38
|
# and logs the user in if found.
|
39
39
|
# Runs as a login source. See 'current_user' method for how it is used.
|
40
40
|
def login_from_cookie
|
41
|
-
user = cookies[:remember_me_token] &&
|
41
|
+
user = cookies[:remember_me_token] && user_class.find_by_remember_me_token(cookies[:remember_me_token])
|
42
42
|
if user && user.remember_me_token?
|
43
43
|
set_remember_me_cookie!(user)
|
44
44
|
@current_user = user
|
@@ -173,6 +173,6 @@ Rails.application.config.sorcery.configure do |config|
|
|
173
173
|
end
|
174
174
|
|
175
175
|
# This line must come after the 'user config' block.
|
176
|
-
config.user_class = User
|
176
|
+
config.user_class = "User" # define which model authenticates
|
177
177
|
# with sorcery.
|
178
178
|
end
|
data/lib/sorcery/model.rb
CHANGED
@@ -15,7 +15,27 @@ module Sorcery
|
|
15
15
|
self.class_eval do
|
16
16
|
extend ClassMethods # included here, before submodules, so they can be overriden by them.
|
17
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)
|
18
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
|
19
39
|
@sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
|
20
40
|
@sorcery_config.submodules.each do |mod|
|
21
41
|
begin
|
@@ -26,28 +46,27 @@ module Sorcery
|
|
26
46
|
end
|
27
47
|
end
|
28
48
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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!
|
34
54
|
self.class_eval do
|
35
55
|
field sorcery_config.username_attribute_name, :type => String
|
36
56
|
field sorcery_config.email_attribute_name, :type => String unless sorcery_config.username_attribute_name == sorcery_config.email_attribute_name
|
37
57
|
field sorcery_config.crypted_password_attribute_name, :type => String
|
38
58
|
field sorcery_config.salt_attribute_name, :type => String
|
39
|
-
end
|
40
|
-
|
41
|
-
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# add virtual password accessor and ORM callbacks.
|
63
|
+
def init_orm_hooks!
|
42
64
|
self.class_eval do
|
43
65
|
attr_accessor @sorcery_config.password_attribute_name
|
44
66
|
attr_protected @sorcery_config.crypted_password_attribute_name, @sorcery_config.salt_attribute_name
|
45
67
|
before_save :encrypt_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? }
|
46
68
|
after_save :clear_virtual_password, :if => Proc.new { |record| record.send(sorcery_config.password_attribute_name).present? }
|
47
69
|
end
|
48
|
-
|
49
|
-
@sorcery_config.after_config << :add_config_inheritance if @sorcery_config.subclasses_inherit_config
|
50
|
-
@sorcery_config.after_config.each { |c| send(c) }
|
51
70
|
end
|
52
71
|
end
|
53
72
|
end
|
@@ -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)
|
@@ -26,7 +26,7 @@ module Sorcery
|
|
26
26
|
::Sorcery::Controller::Config.submodules = submodules
|
27
27
|
::Sorcery::Controller::Config.user_class = nil
|
28
28
|
ActionController::Base.send(:include,::Sorcery::Controller)
|
29
|
-
::Sorcery::Controller::Config.user_class = User
|
29
|
+
::Sorcery::Controller::Config.user_class = "User"
|
30
30
|
|
31
31
|
::Sorcery::Controller::Config.user_config do |user|
|
32
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|
|
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-07-
|
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,8 @@ 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",
|
221
223
|
"spec/shared_examples/user_activation_shared_examples.rb",
|
222
224
|
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
223
225
|
"spec/shared_examples/user_brute_force_protection_shared_examples.rb",
|
@@ -362,6 +364,8 @@ Gem::Specification.new do |s|
|
|
362
364
|
"spec/rails3_mongoid/spec/user_remember_me_spec.rb",
|
363
365
|
"spec/rails3_mongoid/spec/user_reset_password_spec.rb",
|
364
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",
|
365
369
|
"spec/shared_examples/user_activation_shared_examples.rb",
|
366
370
|
"spec/shared_examples/user_activity_logging_shared_examples.rb",
|
367
371
|
"spec/shared_examples/user_brute_force_protection_shared_examples.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
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_examples_for "oauth2_controller" do
|
2
|
+
describe "using 'create_from'" do
|
3
|
+
before(:each) do
|
4
|
+
stub_all_oauth2_requests!
|
5
|
+
User.delete_all
|
6
|
+
Authentication.delete_all
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should create a new user" do
|
10
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
11
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name"})
|
12
|
+
lambda do
|
13
|
+
get :test_create_from_provider, :provider => "facebook"
|
14
|
+
end.should change(User, :count).by(1)
|
15
|
+
User.first.username.should == "Noam Ben Ari"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should support nested attributes" do
|
19
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
20
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "hometown/name"})
|
21
|
+
lambda do
|
22
|
+
get :test_create_from_provider, :provider => "facebook"
|
23
|
+
end.should change(User, :count).by(1)
|
24
|
+
User.first.username.should == "Haifa, Israel"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not crash on missing nested attributes" do
|
28
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
29
|
+
sorcery_controller_external_property_set(:facebook, :user_info_mapping, {:username => "name", :created_at => "does/not/exist"})
|
30
|
+
lambda do
|
31
|
+
get :test_create_from_provider, :provider => "facebook"
|
32
|
+
end.should change(User, :count).by(1)
|
33
|
+
User.first.username.should == "Noam Ben Ari"
|
34
|
+
User.first.created_at.should_not be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_examples_for "oauth_controller" do
|
2
|
+
describe "using 'create_from'" do
|
3
|
+
before(:each) do
|
4
|
+
stub_all_oauth_requests!
|
5
|
+
User.delete_all
|
6
|
+
Authentication.delete_all
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should create a new user" do
|
10
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
11
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
12
|
+
lambda do
|
13
|
+
get :test_create_from_provider, :provider => "twitter"
|
14
|
+
end.should change(User, :count).by(1)
|
15
|
+
User.first.username.should == "nbenari"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should support nested attributes" do
|
19
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
20
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
21
|
+
lambda do
|
22
|
+
get :test_create_from_provider, :provider => "twitter"
|
23
|
+
end.should change(User, :count).by(1)
|
24
|
+
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not crash on missing nested attributes" do
|
28
|
+
sorcery_model_property_set(:authentications_class, Authentication)
|
29
|
+
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text", :created_at => "does/not/exist"})
|
30
|
+
lambda do
|
31
|
+
get :test_create_from_provider, :provider => "twitter"
|
32
|
+
end.should change(User, :count).by(1)
|
33
|
+
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
34
|
+
User.first.created_at.should_not be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/sinatra/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 'MyApp' do
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
describe Sinatra::Application
|
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 Sinatra::Application do
|
63
|
+
it_behaves_like "oauth2_controller"
|
85
64
|
end
|
86
65
|
|
87
66
|
describe Sinatra::Application, "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!
|
@@ -63,30 +64,8 @@ describe Sinatra::Application do
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
describe Sinatra::Application
|
67
|
-
|
68
|
-
stub_all_oauth_requests!
|
69
|
-
User.delete_all
|
70
|
-
Authentication.delete_all
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should create a new user" do
|
74
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
75
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
76
|
-
lambda do
|
77
|
-
get :test_create_from_provider, :provider => "twitter"
|
78
|
-
end.should change(User, :count).by(1)
|
79
|
-
User.first.username.should == "nbenari"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should support nested attributes" do
|
83
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
84
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
85
|
-
lambda do
|
86
|
-
get :test_create_from_provider, :provider => "twitter"
|
87
|
-
end.should change(User, :count).by(1)
|
88
|
-
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
89
|
-
end
|
67
|
+
describe Sinatra::Application do
|
68
|
+
it_behaves_like "oauth_controller"
|
90
69
|
end
|
91
70
|
|
92
71
|
describe Sinatra::Application, "OAuth with User Activation features" do
|
@@ -14,8 +14,8 @@ describe Sinatra::Application 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
|
@@ -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 'MyApp' do
|
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
61
|
-
describe Modular
|
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 Modular do
|
63
|
+
it_behaves_like "oauth2_controller"
|
85
64
|
end
|
86
65
|
|
87
66
|
describe Modular, "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!
|
@@ -63,30 +64,8 @@ describe Modular do
|
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
describe Modular
|
67
|
-
|
68
|
-
stub_all_oauth_requests!
|
69
|
-
User.delete_all
|
70
|
-
Authentication.delete_all
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should create a new user" do
|
74
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
75
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "screen_name"})
|
76
|
-
lambda do
|
77
|
-
get :test_create_from_provider, :provider => "twitter"
|
78
|
-
end.should change(User, :count).by(1)
|
79
|
-
User.first.username.should == "nbenari"
|
80
|
-
end
|
81
|
-
|
82
|
-
it "should support nested attributes" do
|
83
|
-
sorcery_model_property_set(:authentications_class, Authentication)
|
84
|
-
sorcery_controller_external_property_set(:twitter, :user_info_mapping, {:username => "status/text"})
|
85
|
-
lambda do
|
86
|
-
get :test_create_from_provider, :provider => "twitter"
|
87
|
-
end.should change(User, :count).by(1)
|
88
|
-
User.first.username.should == "coming soon to sorcery gem: twitter and facebook authentication support."
|
89
|
-
end
|
67
|
+
describe Modular do
|
68
|
+
it_behaves_like "oauth_controller"
|
90
69
|
end
|
91
70
|
|
92
71
|
describe Modular, "OAuth with User Activation features" do
|
@@ -14,8 +14,8 @@ describe Modular 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
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sorcery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Noam Ben Ari
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-30 00:00:00 +03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -422,6 +422,8 @@ files:
|
|
422
422
|
- spec/rails3_mongoid/spec/user_reset_password_spec.rb
|
423
423
|
- spec/rails3_mongoid/spec/user_spec.rb
|
424
424
|
- spec/rails3_mongoid/vendor/plugins/.gitkeep
|
425
|
+
- spec/shared_examples/controller_oauth2_shared_examples.rb
|
426
|
+
- spec/shared_examples/controller_oauth_shared_examples.rb
|
425
427
|
- spec/shared_examples/user_activation_shared_examples.rb
|
426
428
|
- spec/shared_examples/user_activity_logging_shared_examples.rb
|
427
429
|
- spec/shared_examples/user_brute_force_protection_shared_examples.rb
|
@@ -588,6 +590,8 @@ test_files:
|
|
588
590
|
- spec/rails3_mongoid/spec/user_remember_me_spec.rb
|
589
591
|
- spec/rails3_mongoid/spec/user_reset_password_spec.rb
|
590
592
|
- spec/rails3_mongoid/spec/user_spec.rb
|
593
|
+
- spec/shared_examples/controller_oauth2_shared_examples.rb
|
594
|
+
- spec/shared_examples/controller_oauth_shared_examples.rb
|
591
595
|
- spec/shared_examples/user_activation_shared_examples.rb
|
592
596
|
- spec/shared_examples/user_activity_logging_shared_examples.rb
|
593
597
|
- spec/shared_examples/user_brute_force_protection_shared_examples.rb
|