sorcery 0.6.1 → 0.7.10
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/.travis.yml +2 -0
- data/Gemfile +2 -23
- data/Gemfile.lock +105 -77
- data/README.rdoc +32 -59
- data/Rakefile +29 -1
- data/VERSION +1 -1
- data/lib/generators/sorcery/USAGE +22 -0
- data/lib/generators/sorcery/install_generator.rb +77 -0
- data/lib/generators/sorcery/templates/initializer.rb +406 -0
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +17 -0
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +13 -0
- data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/core.rb +3 -3
- data/lib/generators/{sorcery_migration/templates → sorcery/templates/migration}/external.rb +1 -1
- data/lib/generators/sorcery/templates/migration/remember_me.rb +15 -0
- data/lib/generators/sorcery/templates/migration/reset_password.rb +17 -0
- data/lib/generators/sorcery/templates/migration/user_activation.rb +17 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +24 -10
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +3 -2
- data/lib/sorcery/controller/submodules/external/protocols/certs/ca-bundle.crt +5182 -0
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +28 -9
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +12 -4
- data/lib/sorcery/controller/submodules/external/providers/github.rb +89 -0
- data/lib/sorcery/controller/submodules/external/providers/google.rb +90 -0
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +91 -0
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +8 -2
- data/lib/sorcery/controller/submodules/external.rb +17 -4
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +1 -1
- data/lib/sorcery/controller/submodules/remember_me.rb +26 -15
- data/lib/sorcery/controller/submodules/session_timeout.rb +4 -4
- data/lib/sorcery/controller.rb +61 -38
- data/lib/sorcery/crypto_providers/aes256.rb +7 -3
- data/lib/sorcery/engine.rb +1 -0
- data/lib/sorcery/model/adapters/active_record.rb +17 -1
- data/lib/sorcery/model/adapters/mongo_mapper.rb +54 -0
- data/lib/sorcery/model/adapters/mongoid.rb +22 -4
- data/lib/sorcery/model/submodules/activity_logging.rb +4 -4
- data/lib/sorcery/model/submodules/brute_force_protection.rb +53 -14
- data/lib/sorcery/model/submodules/remember_me.rb +10 -3
- data/lib/sorcery/model/submodules/reset_password.rb +26 -11
- data/lib/sorcery/model/submodules/user_activation.rb +28 -10
- data/lib/sorcery/model/temporary_token.rb +8 -1
- data/lib/sorcery/model.rb +51 -19
- data/lib/sorcery/test_helpers/internal/rails.rb +1 -1
- data/lib/sorcery/test_helpers/rails.rb +2 -2
- data/lib/sorcery.rb +8 -7
- data/sorcery.gemspec +110 -223
- data/spec/Gemfile +1 -1
- data/spec/Gemfile.lock +26 -26
- data/spec/README.md +31 -0
- data/spec/rails3/Gemfile +5 -3
- data/spec/rails3/Gemfile.lock +74 -48
- data/spec/rails3/app/controllers/application_controller.rb +70 -23
- data/spec/rails3/app/mailers/sorcery_mailer.rb +7 -0
- data/spec/rails3/app/views/application/index.html.erb +17 -0
- data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
- data/spec/rails3/config/environments/in_memory.rb +35 -0
- data/spec/rails3/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +2 -0
- data/spec/rails3/spec/controller_activity_logging_spec.rb +33 -3
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +25 -3
- data/spec/rails3/spec/controller_oauth2_spec.rb +170 -25
- data/spec/rails3/spec/controller_remember_me_spec.rb +37 -6
- data/spec/rails3/spec/controller_session_timeout_spec.rb +4 -4
- data/spec/rails3/spec/controller_spec.rb +60 -2
- data/spec/rails3/spec/integration_spec.rb +23 -0
- data/spec/rails3/spec/spec_helper.rb +6 -5
- data/spec/rails3_mongo_mapper/.gitignore +4 -0
- data/spec/rails3_mongo_mapper/.rspec +1 -0
- data/spec/{sinatra_modular → rails3_mongo_mapper}/Gemfile +6 -5
- data/spec/rails3_mongo_mapper/Gemfile.lock +154 -0
- data/spec/{sinatra → rails3_mongo_mapper}/Rakefile +3 -3
- data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +108 -0
- data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +2 -0
- data/spec/rails3_mongo_mapper/app/models/authentication.rb +6 -0
- data/spec/rails3_mongo_mapper/app/models/user.rb +5 -0
- data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +14 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +17 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +9 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.html.erb +17 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +9 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +16 -0
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +8 -0
- data/spec/rails3_mongo_mapper/config/application.rb +51 -0
- data/spec/rails3_mongo_mapper/config/boot.rb +13 -0
- data/spec/rails3_mongo_mapper/config/environment.rb +5 -0
- data/spec/rails3_mongo_mapper/config/environments/development.rb +30 -0
- data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongo_mapper/config/environments/production.rb +49 -0
- data/spec/rails3_mongo_mapper/config/environments/test.rb +35 -0
- data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +10 -0
- data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +5 -0
- data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +2 -0
- data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +7 -0
- data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +8 -0
- data/spec/rails3_mongo_mapper/config/locales/en.yml +5 -0
- data/spec/rails3_mongo_mapper/config/routes.rb +59 -0
- data/spec/rails3_mongo_mapper/config.ru +4 -0
- data/spec/rails3_mongo_mapper/db/schema.rb +23 -0
- data/spec/rails3_mongo_mapper/db/seeds.rb +7 -0
- data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/public/404.html +26 -0
- data/spec/rails3_mongo_mapper/public/422.html +26 -0
- data/spec/rails3_mongo_mapper/public/500.html +26 -0
- data/spec/rails3_mongo_mapper/public/favicon.ico +0 -0
- data/spec/rails3_mongo_mapper/public/images/rails.png +0 -0
- data/spec/rails3_mongo_mapper/public/javascripts/application.js +2 -0
- data/spec/rails3_mongo_mapper/public/javascripts/controls.js +965 -0
- data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +974 -0
- data/spec/rails3_mongo_mapper/public/javascripts/effects.js +1123 -0
- data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +6001 -0
- data/spec/rails3_mongo_mapper/public/javascripts/rails.js +175 -0
- data/spec/rails3_mongo_mapper/public/robots.txt +5 -0
- data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/script/rails +6 -0
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +163 -0
- data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +27 -0
- data/spec/rails3_mongo_mapper/spec/spec_helper.rb +55 -0
- data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +9 -0
- data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +8 -0
- data/spec/rails3_mongo_mapper/spec/user_spec.rb +37 -0
- data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongoid/Gemfile +2 -1
- data/spec/rails3_mongoid/Gemfile.lock +46 -45
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +5 -0
- data/spec/rails3_mongoid/config/mongoid.yml +1 -1
- data/spec/rails3_mongoid/script/rails +0 -0
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +105 -0
- data/spec/rails3_mongoid/spec/controller_spec.rb +174 -0
- data/spec/rails3_mongoid/spec/user_spec.rb +1 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +72 -42
- data/spec/shared_examples/user_remember_me_shared_examples.rb +2 -1
- data/spec/shared_examples/user_reset_password_shared_examples.rb +81 -28
- data/spec/shared_examples/user_shared_examples.rb +36 -8
- data/spec/sorcery_crypto_providers_spec.rb +5 -1
- metadata +239 -346
- data/lib/generators/sorcery_migration/sorcery_migration_generator.rb +0 -24
- data/lib/generators/sorcery_migration/templates/activity_logging.rb +0 -17
- data/lib/generators/sorcery_migration/templates/brute_force_protection.rb +0 -11
- data/lib/generators/sorcery_migration/templates/remember_me.rb +0 -15
- data/lib/generators/sorcery_migration/templates/reset_password.rb +0 -13
- data/lib/generators/sorcery_migration/templates/user_activation.rb +0 -17
- data/lib/sorcery/controller/adapters/sinatra.rb +0 -104
- data/lib/sorcery/initializers/initializer.rb +0 -178
- data/lib/sorcery/sinatra.rb +0 -4
- data/lib/sorcery/test_helpers/internal/sinatra.rb +0 -74
- data/lib/sorcery/test_helpers/internal/sinatra_modular.rb +0 -74
- data/lib/sorcery/test_helpers/sinatra.rb +0 -88
- data/spec/rails3/Rakefile.unused +0 -7
- data/spec/rails3/public/index.html +0 -239
- data/spec/sinatra/Gemfile +0 -15
- data/spec/sinatra/Gemfile.lock +0 -117
- data/spec/sinatra/authentication.rb +0 -3
- data/spec/sinatra/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
- data/spec/sinatra/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
- data/spec/sinatra/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
- data/spec/sinatra/db/migrate/core/20101224223620_create_users.rb +0 -16
- data/spec/sinatra/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/sinatra/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
- data/spec/sinatra/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
- data/spec/sinatra/filters.rb +0 -27
- data/spec/sinatra/modular.rb +0 -157
- data/spec/sinatra/myapp.rb +0 -133
- data/spec/sinatra/spec/controller_activity_logging_spec.rb +0 -85
- data/spec/sinatra/spec/controller_brute_force_protection_spec.rb +0 -70
- data/spec/sinatra/spec/controller_http_basic_auth_spec.rb +0 -53
- data/spec/sinatra/spec/controller_oauth2_spec.rb +0 -99
- data/spec/sinatra/spec/controller_oauth_spec.rb +0 -100
- data/spec/sinatra/spec/controller_remember_me_spec.rb +0 -64
- data/spec/sinatra/spec/controller_session_timeout_spec.rb +0 -57
- data/spec/sinatra/spec/controller_spec.rb +0 -120
- data/spec/sinatra/spec/spec_helper.rb +0 -45
- data/spec/sinatra/user.rb +0 -6
- data/spec/sinatra/views/test_login.erb +0 -4
- data/spec/sinatra_modular/Gemfile.lock +0 -117
- data/spec/sinatra_modular/Rakefile +0 -11
- data/spec/sinatra_modular/authentication.rb +0 -3
- data/spec/sinatra_modular/db/migrate/activation/20101224223622_add_activation_to_users.rb +0 -17
- data/spec/sinatra_modular/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +0 -17
- data/spec/sinatra_modular/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -11
- data/spec/sinatra_modular/db/migrate/core/20101224223620_create_users.rb +0 -16
- data/spec/sinatra_modular/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/sinatra_modular/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -15
- data/spec/sinatra_modular/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -13
- data/spec/sinatra_modular/filters.rb +0 -27
- data/spec/sinatra_modular/modular.rb +0 -157
- data/spec/sinatra_modular/myapp.rb +0 -133
- data/spec/sinatra_modular/sorcery_mailer.rb +0 -25
- data/spec/sinatra_modular/spec_modular/controller_activity_logging_spec.rb +0 -85
- data/spec/sinatra_modular/spec_modular/controller_brute_force_protection_spec.rb +0 -70
- data/spec/sinatra_modular/spec_modular/controller_http_basic_auth_spec.rb +0 -53
- data/spec/sinatra_modular/spec_modular/controller_oauth2_spec.rb +0 -99
- data/spec/sinatra_modular/spec_modular/controller_oauth_spec.rb +0 -100
- data/spec/sinatra_modular/spec_modular/controller_remember_me_spec.rb +0 -64
- data/spec/sinatra_modular/spec_modular/controller_session_timeout_spec.rb +0 -57
- data/spec/sinatra_modular/spec_modular/controller_spec.rb +0 -116
- data/spec/sinatra_modular/spec_modular/spec.opts +0 -2
- data/spec/sinatra_modular/spec_modular/spec_helper.rb +0 -51
- data/spec/sinatra_modular/user.rb +0 -6
- data/spec/sinatra_modular/views/test_login.erb +0 -4
- /data/spec/{sinatra → rails3_mongo_mapper/app/mailers}/sorcery_mailer.rb +0 -0
- /data/spec/{sinatra → rails3_mongo_mapper}/spec/spec.opts +0 -0
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
require 'rails/generators'
|
|
2
|
-
require 'rails/generators/migration'
|
|
3
|
-
|
|
4
|
-
class SorceryMigrationGenerator < Rails::Generators::Base
|
|
5
|
-
include Rails::Generators::Migration
|
|
6
|
-
|
|
7
|
-
source_root File.join(File.dirname(__FILE__), 'templates')
|
|
8
|
-
argument :submodules, :type => :array, :required => true
|
|
9
|
-
|
|
10
|
-
def self.next_migration_number(dirname)
|
|
11
|
-
if ActiveRecord::Base.timestamped_migrations
|
|
12
|
-
Time.new.utc.strftime("%Y%m%d%H%M%S")
|
|
13
|
-
else
|
|
14
|
-
"%.3d" % (current_migration_number(dirname) + 1)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def create_migration_file
|
|
19
|
-
self.submodules.each do |submodule|
|
|
20
|
-
migration_template "#{submodule}.rb", "db/migrate/sorcery_#{submodule}.rb"
|
|
21
|
-
sleep 1 # for the timestamp to change
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class SorceryActivityLogging < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :last_login_at, :datetime, :default => nil
|
|
4
|
-
add_column :users, :last_logout_at, :datetime, :default => nil
|
|
5
|
-
add_column :users, :last_activity_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :users, [:last_logout_at, :last_activity_at]
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.down
|
|
11
|
-
remove_index :users, [:last_logout_at, :last_activity_at]
|
|
12
|
-
|
|
13
|
-
remove_column :users, :last_activity_at
|
|
14
|
-
remove_column :users, :last_logout_at
|
|
15
|
-
remove_column :users, :last_login_at
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
class SorceryBruteForceProtection < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :failed_logins_count, :integer, :default => 0
|
|
4
|
-
add_column :users, :lock_expires_at, :datetime, :default => nil
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def self.down
|
|
8
|
-
remove_column :users, :lock_expires_at
|
|
9
|
-
remove_column :users, :failed_logins_count
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
class SorceryRememberMe < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :remember_me_token, :string, :default => nil
|
|
4
|
-
add_column :users, :remember_me_token_expires_at, :datetime, :default => nil
|
|
5
|
-
|
|
6
|
-
add_index :users, :remember_me_token
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.down
|
|
10
|
-
remove_index :users, :remember_me_token
|
|
11
|
-
|
|
12
|
-
remove_column :users, :remember_me_token_expires_at
|
|
13
|
-
remove_column :users, :remember_me_token
|
|
14
|
-
end
|
|
15
|
-
end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
class SorceryResetPassword < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :reset_password_token, :string, :default => nil
|
|
4
|
-
add_column :users, :reset_password_token_expires_at, :datetime, :default => nil
|
|
5
|
-
add_column :users, :reset_password_email_sent_at, :datetime, :default => nil
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def self.down
|
|
9
|
-
remove_column :users, :reset_password_email_sent_at
|
|
10
|
-
remove_column :users, :reset_password_token_expires_at
|
|
11
|
-
remove_column :users, :reset_password_token
|
|
12
|
-
end
|
|
13
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
class SorceryUserActivation < ActiveRecord::Migration
|
|
2
|
-
def self.up
|
|
3
|
-
add_column :users, :activation_state, :string, :default => nil
|
|
4
|
-
add_column :users, :activation_token, :string, :default => nil
|
|
5
|
-
add_column :users, :activation_token_expires_at, :datetime, :default => nil
|
|
6
|
-
|
|
7
|
-
add_index :users, :activation_token
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def self.down
|
|
11
|
-
remove_index :users, :activation_token
|
|
12
|
-
|
|
13
|
-
remove_column :users, :activation_token_expires_at
|
|
14
|
-
remove_column :users, :activation_token
|
|
15
|
-
remove_column :users, :activation_state
|
|
16
|
-
end
|
|
17
|
-
end
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Adapters
|
|
4
|
-
# This module does the magic of translating Rails commands to Sinatra.
|
|
5
|
-
# This way the Rails code doesn't change, but it actually now calls Sinatra calls.
|
|
6
|
-
module Sinatra
|
|
7
|
-
def self.included(base)
|
|
8
|
-
base.class_eval do
|
|
9
|
-
class << self
|
|
10
|
-
# prepend a filter
|
|
11
|
-
def prepend_filter(type, path = nil, options = {}, &block)
|
|
12
|
-
return filters[type].unshift block unless path
|
|
13
|
-
path, options = //, path if path.respond_to?(:each_pair)
|
|
14
|
-
block, *arguments = compile!(type, path, block, options)
|
|
15
|
-
prepend_filter(type) do
|
|
16
|
-
process_route(*arguments) { instance_eval(&block) }
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def after_filter(filter)
|
|
21
|
-
after do
|
|
22
|
-
send(filter)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
::Sinatra::Request.class_eval do
|
|
29
|
-
def authorization
|
|
30
|
-
env['HTTP_AUTHORIZATION'] ||
|
|
31
|
-
env['X-HTTP_AUTHORIZATION'] ||
|
|
32
|
-
env['X_HTTP_AUTHORIZATION'] ||
|
|
33
|
-
env['REDIRECT_X_HTTP_AUTHORIZATION'] || nil
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
base.send(:include, SorceryHelpers)
|
|
38
|
-
base.send(:include, InstanceMethods)
|
|
39
|
-
base.extend(ClassMethods)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
module SorceryHelpers
|
|
43
|
-
|
|
44
|
-
def request_http_basic_authentication(realm)
|
|
45
|
-
response.header['WWW-Authenticate'] = %(Basic realm="#{realm}")
|
|
46
|
-
response.status = 401
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def authenticate_with_http_basic(&blk)
|
|
50
|
-
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
|
51
|
-
yield @auth.credentials if (@auth.provided? && @auth.basic? && @auth.credentials)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
module InstanceMethods
|
|
57
|
-
def reset_session
|
|
58
|
-
session.clear
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def redirect_to(*args)
|
|
62
|
-
args.pop if args.last.is_a?(Hash)
|
|
63
|
-
redirect(*args)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def root_path
|
|
67
|
-
'/'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
::Sinatra.helpers do
|
|
71
|
-
include SorceryHelpers
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def cookies
|
|
75
|
-
@cookie_proxy ||= CookieProxy.new(request, response)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
class CookieProxy
|
|
80
|
-
def initialize(request, response)
|
|
81
|
-
@request = request
|
|
82
|
-
@response = response
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def [](key)
|
|
86
|
-
@request.cookies[key.to_s]
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def []=(key, value)
|
|
90
|
-
@response.set_cookie(key, value)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
module ClassMethods
|
|
95
|
-
def prepend_before_filter(filter)
|
|
96
|
-
prepend_filter(:before) do
|
|
97
|
-
send(filter)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
end
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
# The first thing you need to configure is which modules you need in your app.
|
|
2
|
-
# The default is nothing which will include only core features (password encryption, login/logout).
|
|
3
|
-
# Available submodules are: :user_activation, :http_basic_auth, :remember_me,
|
|
4
|
-
# :reset_password, :session_timeout, :brute_force_protection, :activity_logging, :external
|
|
5
|
-
Rails.application.config.sorcery.submodules = []
|
|
6
|
-
|
|
7
|
-
# Here you can configure each submodule's features.
|
|
8
|
-
Rails.application.config.sorcery.configure do |config|
|
|
9
|
-
# -- core --
|
|
10
|
-
# config.not_authenticated_action = :not_authenticated # what controller action to call for
|
|
11
|
-
# non-authenticated users.
|
|
12
|
-
# You can also override 'not_authenticated'
|
|
13
|
-
# instead.
|
|
14
|
-
|
|
15
|
-
# config.save_return_to_url = true # when a non logged in user tries to enter
|
|
16
|
-
# a page that requires login,
|
|
17
|
-
# save the URL he wanted to reach,
|
|
18
|
-
# and send him there after login, using
|
|
19
|
-
# 'redirect_back_or_to'.
|
|
20
|
-
|
|
21
|
-
# -- session timeout --
|
|
22
|
-
# config.session_timeout = 3600 # how long in seconds to keep the session alive.
|
|
23
|
-
# config.session_timeout_from_last_action = false # use the last action as the beginning of
|
|
24
|
-
# session timeout.
|
|
25
|
-
|
|
26
|
-
# -- http_basic_auth --
|
|
27
|
-
# config.controller_to_realm_map = {"application" => "Application"} # What realm to display for which controller name.
|
|
28
|
-
# For example {"My App" => "Application"}
|
|
29
|
-
|
|
30
|
-
# -- external --
|
|
31
|
-
# config.external_providers = [] # What providers are supported by this app,
|
|
32
|
-
# i.e. [:twitter, :facebook] .
|
|
33
|
-
#
|
|
34
|
-
# config.twitter.key = "eYVNBjBDi33aa9GkA3w"
|
|
35
|
-
# config.twitter.secret = "XpbeSdCoaKSmQGSeokz5qcUATClRW5u08QWNfv71N8"
|
|
36
|
-
# config.twitter.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=twitter"
|
|
37
|
-
# config.twitter.user_info_mapping = {:email => "screen_name"}
|
|
38
|
-
#
|
|
39
|
-
# config.facebook.key = "34cebc81c08a521bc66e212f947d73ec"
|
|
40
|
-
# config.facebook.secret = "5b458d179f61d4f036ee66a497ffbcd0"
|
|
41
|
-
# config.facebook.callback_url = "http://0.0.0.0:3000/oauth/callback?provider=facebook"
|
|
42
|
-
# config.facebook.user_info_mapping = {:email => "name"}
|
|
43
|
-
|
|
44
|
-
# --- user config ---
|
|
45
|
-
config.user_config do |user|
|
|
46
|
-
# -- core --
|
|
47
|
-
# user.username_attribute_name = :username # change default username
|
|
48
|
-
# attribute, for example,
|
|
49
|
-
# to use :email as the login.
|
|
50
|
-
|
|
51
|
-
# user.password_attribute_name = :password # change *virtual* password
|
|
52
|
-
# attribute, the one which is used
|
|
53
|
-
# until an encrypted one is
|
|
54
|
-
# generated.
|
|
55
|
-
|
|
56
|
-
# user.email_attribute_name = :email # change default email attribute.
|
|
57
|
-
|
|
58
|
-
# user.crypted_password_attribute_name = :crypted_password # change default crypted_password
|
|
59
|
-
# attribute.
|
|
60
|
-
|
|
61
|
-
# user.salt_join_token = "" # what pattern to use to join the
|
|
62
|
-
# password with the salt
|
|
63
|
-
|
|
64
|
-
# user.salt_attribute_name = :salt # change default salt attribute.
|
|
65
|
-
|
|
66
|
-
# user.stretches = nil # how many times to apply
|
|
67
|
-
# encryption to the password.
|
|
68
|
-
|
|
69
|
-
# user.encryption_key = nil # encryption key used to encrypt
|
|
70
|
-
# reversible encryptions such as
|
|
71
|
-
# AES256.
|
|
72
|
-
|
|
73
|
-
# user.custom_encryption_provider = nil # use an external encryption
|
|
74
|
-
# class.
|
|
75
|
-
|
|
76
|
-
# user.encryption_algorithm = :bcrypt # encryption algorithm name. See
|
|
77
|
-
# 'encryption_algorithm=' for
|
|
78
|
-
# available options.
|
|
79
|
-
|
|
80
|
-
# user.subclasses_inherit_config = false # make this configuration
|
|
81
|
-
# inheritable for subclasses.
|
|
82
|
-
# Useful for ActiveRecord's STI.
|
|
83
|
-
|
|
84
|
-
# -- user_activation --
|
|
85
|
-
# user.activation_state_attribute_name = :activation_state # the attribute name to hold
|
|
86
|
-
# activation state
|
|
87
|
-
# (active/pending).
|
|
88
|
-
|
|
89
|
-
# user.activation_token_attribute_name = :activation_token # the attribute name to hold
|
|
90
|
-
# activation code (sent by email).
|
|
91
|
-
|
|
92
|
-
# user.activation_token_expires_at_attribute_name = :activation_token_expires_at # the attribute name to hold
|
|
93
|
-
# activation code expiration date.
|
|
94
|
-
|
|
95
|
-
# user.activation_token_expiration_period = nil # how many seconds before the
|
|
96
|
-
# activation code expires. nil for
|
|
97
|
-
# never expires.
|
|
98
|
-
|
|
99
|
-
# user.user_activation_mailer = nil # your mailer class. Required.
|
|
100
|
-
|
|
101
|
-
# user.activation_needed_email_method_name = :activation_needed_email # activation needed email method
|
|
102
|
-
# on your mailer class.
|
|
103
|
-
|
|
104
|
-
# user.activation_success_email_method_name = :activation_success_email # activation success email method
|
|
105
|
-
# on your mailer class.
|
|
106
|
-
|
|
107
|
-
# user.prevent_non_active_users_to_login = true # do you want to prevent or allow
|
|
108
|
-
# users that did not activate by
|
|
109
|
-
# email to login?
|
|
110
|
-
|
|
111
|
-
# -- reset_password --
|
|
112
|
-
# user.reset_password_token_attribute_name = :reset_password_token # reset password code
|
|
113
|
-
# attribute name.
|
|
114
|
-
|
|
115
|
-
# user.reset_password_token_expires_at_attribute_name = :reset_password_token_expires_at # expires at attribute
|
|
116
|
-
# name.
|
|
117
|
-
|
|
118
|
-
# user.reset_password_email_sent_at_attribute_name = :reset_password_email_sent_at # when was email sent,
|
|
119
|
-
# used for hammering
|
|
120
|
-
# protection.
|
|
121
|
-
|
|
122
|
-
# user.reset_password_mailer = nil # mailer class. Needed.
|
|
123
|
-
|
|
124
|
-
# user.reset_password_email_method_name = :reset_password_email # reset password email
|
|
125
|
-
# method on your mailer
|
|
126
|
-
# class.
|
|
127
|
-
|
|
128
|
-
# user.reset_password_expiration_period = nil # how many seconds
|
|
129
|
-
# before the reset
|
|
130
|
-
# request expires. nil
|
|
131
|
-
# for never expires.
|
|
132
|
-
|
|
133
|
-
# user.reset_password_time_between_emails = 5 * 60 # hammering protection,
|
|
134
|
-
# how long to wait
|
|
135
|
-
# before allowing
|
|
136
|
-
# another email to be
|
|
137
|
-
# sent.
|
|
138
|
-
|
|
139
|
-
# -- brute_force_protection --
|
|
140
|
-
# user.failed_logins_count_attribute_name = :failed_logins_count # failed logins attribute name.
|
|
141
|
-
|
|
142
|
-
# user.lock_expires_at_attribute_name = :lock_expires_at # this field indicates whether
|
|
143
|
-
# user is banned and when it will
|
|
144
|
-
# be active again.
|
|
145
|
-
|
|
146
|
-
# user.consecutive_login_retries_amount_limit = 50 # how many failed logins allowed.
|
|
147
|
-
|
|
148
|
-
# user.login_lock_time_period = 60 * 60 # how long the user should be
|
|
149
|
-
# banned. in seconds. 0 for
|
|
150
|
-
# permanent.
|
|
151
|
-
|
|
152
|
-
# -- activity logging --
|
|
153
|
-
# user.last_login_at_attribute_name = :last_login_at # last login attribute name.
|
|
154
|
-
# user.last_logout_at_attribute_name = :last_logout_at # last logout attribute name.
|
|
155
|
-
# user.last_activity_at_attribute_name = :last_activity_at # last activity attribute name.
|
|
156
|
-
# user.activity_timeout = 10 * 60 # how long since last activity is
|
|
157
|
-
# the user defined logged out?
|
|
158
|
-
|
|
159
|
-
# -- external --
|
|
160
|
-
# user.authentications_class = nil # class which holds the various
|
|
161
|
-
# external provider data for this
|
|
162
|
-
# user.
|
|
163
|
-
|
|
164
|
-
# user.authentications_user_id_attribute_name = :user_id # user's identifier in
|
|
165
|
-
# authentications class.
|
|
166
|
-
|
|
167
|
-
# user.provider_attribute_name = :provider # provider's identifier in
|
|
168
|
-
# authentications class.
|
|
169
|
-
|
|
170
|
-
# user.provider_uid_attribute_name = :uid # user's external unique
|
|
171
|
-
# identifier in authentications
|
|
172
|
-
# class.
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
# This line must come after the 'user config' block.
|
|
176
|
-
config.user_class = "User" # define which model authenticates
|
|
177
|
-
# with sorcery.
|
|
178
|
-
end
|
data/lib/sorcery/sinatra.rb
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Internal
|
|
4
|
-
module Sinatra
|
|
5
|
-
include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
|
|
6
|
-
include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
|
|
7
|
-
|
|
8
|
-
class ::Sinatra::Application
|
|
9
|
-
class << self
|
|
10
|
-
attr_accessor :sorcery_vars
|
|
11
|
-
end
|
|
12
|
-
@sorcery_vars = {}
|
|
13
|
-
|
|
14
|
-
# NOTE: see before and after test filters in filters.rb
|
|
15
|
-
|
|
16
|
-
def save_instance_vars
|
|
17
|
-
instance_variables.each do |var|
|
|
18
|
-
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
::RSpec::Matchers.define :redirect_to do |expected|
|
|
24
|
-
match do |actual|
|
|
25
|
-
actual.status == 302 && actual.location == expected
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clear_user_without_logout
|
|
30
|
-
get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def assigns
|
|
34
|
-
::Sinatra::Application.sorcery_vars
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
38
|
-
reload_user_class
|
|
39
|
-
|
|
40
|
-
# return to no-module configuration
|
|
41
|
-
::Sorcery::Controller::Config.init!
|
|
42
|
-
::Sorcery::Controller::Config.reset!
|
|
43
|
-
|
|
44
|
-
# clear all filters
|
|
45
|
-
::Sinatra::Application.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
-
load File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters.rb')
|
|
47
|
-
::Sinatra::Application.send(:include, ::Filters)
|
|
48
|
-
|
|
49
|
-
# configure
|
|
50
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
51
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
52
|
-
::Sinatra::Application.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
|
-
::Sinatra::Application.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = "User"
|
|
55
|
-
|
|
56
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
57
|
-
options.each do |property, value|
|
|
58
|
-
user.send(:"#{property}=", value)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
User.authenticates_with_sorcery!
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def sorcery_controller_property_set(property, value)
|
|
65
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def sorcery_controller_external_property_set(provider, property, value)
|
|
69
|
-
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Internal
|
|
4
|
-
module SinatraModular
|
|
5
|
-
include ::Sorcery::TestHelpers::Sinatra::CookieSessionMethods
|
|
6
|
-
include ::Sorcery::TestHelpers::Sinatra::InstanceMethods
|
|
7
|
-
|
|
8
|
-
class ::Modular
|
|
9
|
-
class << self
|
|
10
|
-
attr_accessor :sorcery_vars
|
|
11
|
-
end
|
|
12
|
-
@sorcery_vars = {}
|
|
13
|
-
|
|
14
|
-
# NOTE: see before and after test filters in filters.rb
|
|
15
|
-
|
|
16
|
-
def save_instance_vars
|
|
17
|
-
instance_variables.each do |var|
|
|
18
|
-
self.class.sorcery_vars[:"#{var.to_s.delete("@")}"] = instance_variable_get(var)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
::RSpec::Matchers.define :redirect_to do |expected|
|
|
24
|
-
match do |actual|
|
|
25
|
-
actual.status == 302 && actual.location == expected
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def clear_user_without_logout
|
|
30
|
-
get_sinatra_app(subject).instance_variable_set(:@current_user, nil)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def assigns
|
|
34
|
-
::Modular.sorcery_vars
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def sorcery_reload!(submodules = [], options = {})
|
|
38
|
-
reload_user_class
|
|
39
|
-
|
|
40
|
-
# return to no-module configuration
|
|
41
|
-
::Sorcery::Controller::Config.init!
|
|
42
|
-
::Sorcery::Controller::Config.reset!
|
|
43
|
-
|
|
44
|
-
# clear all filters
|
|
45
|
-
::Sinatra::Base.instance_variable_set(:@filters, {:before => [], :after => []})
|
|
46
|
-
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec', 'sinatra', 'filters')
|
|
47
|
-
::Sinatra::Base.send(:include, ::Filters)
|
|
48
|
-
|
|
49
|
-
# configure
|
|
50
|
-
::Sorcery::Controller::Config.submodules = submodules
|
|
51
|
-
::Sorcery::Controller::Config.user_class = nil
|
|
52
|
-
::Sinatra::Base.send(:include, Sorcery::Controller::Adapters::Sinatra)
|
|
53
|
-
::Sinatra::Base.send(:include, Sorcery::Controller)
|
|
54
|
-
::Sorcery::Controller::Config.user_class = "User"
|
|
55
|
-
|
|
56
|
-
::Sorcery::Controller::Config.user_config do |user|
|
|
57
|
-
options.each do |property, value|
|
|
58
|
-
user.send(:"#{property}=", value)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
User.authenticates_with_sorcery!
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def sorcery_controller_property_set(property, value)
|
|
65
|
-
::Sorcery::Controller::Config.send(:"#{property}=", value)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def sorcery_controller_external_property_set(provider, property, value)
|
|
69
|
-
::Sorcery::Controller::Config.send(provider).send(:"#{property}=", value)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module TestHelpers
|
|
3
|
-
module Sinatra
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.send(:include, InstanceMethods)
|
|
6
|
-
base.send(:include, CookieSessionMethods)
|
|
7
|
-
::Sinatra::Base.class_eval do
|
|
8
|
-
class << self
|
|
9
|
-
attr_accessor :rack_test_session
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.inherited(subclass)
|
|
13
|
-
super
|
|
14
|
-
subclass.class_eval do
|
|
15
|
-
class << self
|
|
16
|
-
attr_accessor :rack_test_session
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
include CookieSessionMethods
|
|
22
|
-
|
|
23
|
-
def rack_test_session
|
|
24
|
-
self.class.rack_test_session
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module InstanceMethods
|
|
30
|
-
def get_sinatra_app(app)
|
|
31
|
-
while !app.kind_of? ::Sinatra::Base do
|
|
32
|
-
app = app.instance_variable_get(:@app)
|
|
33
|
-
end
|
|
34
|
-
app
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def login_user(user=nil)
|
|
38
|
-
user ||= @user
|
|
39
|
-
get_sinatra_app(app).send(:login_user, user)
|
|
40
|
-
get_sinatra_app(app).send(:after_login!, user, [user.send(user.sorcery_config.username_attribute_name), 'secret'])
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def logout_user
|
|
44
|
-
get_sinatra_app(app).send(:logout)
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
module CookieSessionMethods
|
|
49
|
-
class SessionData
|
|
50
|
-
def initialize(cookies)
|
|
51
|
-
@cookies = cookies
|
|
52
|
-
@data = cookies['rack.session']
|
|
53
|
-
if @data
|
|
54
|
-
@data = @data.unpack("m*").first
|
|
55
|
-
@data = Marshal.load(@data)
|
|
56
|
-
else
|
|
57
|
-
@data = {}
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def [](key)
|
|
62
|
-
@data[key]
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def []=(key, value)
|
|
66
|
-
@data[key] = value
|
|
67
|
-
session_data = Marshal.dump(@data)
|
|
68
|
-
session_data = [session_data].pack("m*")
|
|
69
|
-
@cookies.merge("rack.session=#{Rack::Utils.escape(session_data)}", URI.parse("//example.org//"))
|
|
70
|
-
raise "session variable not set" unless @cookies['rack.session'] == session_data
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def clear
|
|
74
|
-
@data = {}
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
def session
|
|
79
|
-
SessionData.new(cookies)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def cookies
|
|
83
|
-
rack_test_session.instance_variable_get(:@rack_mock_session).cookie_jar
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
data/spec/rails3/Rakefile.unused
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
|
2
|
-
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
|
3
|
-
|
|
4
|
-
require File.expand_path('../config/application', __FILE__)
|
|
5
|
-
require 'rake'
|
|
6
|
-
|
|
7
|
-
AppRoot::Application.load_tasks
|