sorcery 0.8.1 → 0.9.1
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.
- checksums.yaml +7 -0
- data/.gitignore +56 -0
- data/.travis.yml +130 -1
- data/CHANGELOG.md +279 -0
- data/Gemfile +18 -23
- data/README.md +372 -0
- data/Rakefile +3 -78
- data/gemfiles/active_record-rails40.gemfile +7 -0
- data/gemfiles/active_record-rails41.gemfile +7 -0
- data/gemfiles/mongo_mapper-rails40.gemfile +9 -0
- data/gemfiles/mongo_mapper-rails41.gemfile +9 -0
- data/gemfiles/mongoid-rails40.gemfile +9 -0
- data/gemfiles/mongoid-rails41.gemfile +9 -0
- data/gemfiles/mongoid3-rails32.gemfile +9 -0
- data/lib/generators/sorcery/USAGE +1 -1
- data/lib/generators/sorcery/helpers.rb +40 -0
- data/lib/generators/sorcery/install_generator.rb +38 -20
- data/lib/generators/sorcery/templates/initializer.rb +53 -16
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +3 -10
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -7
- data/lib/generators/sorcery/templates/migration/core.rb +5 -8
- data/lib/generators/sorcery/templates/migration/external.rb +3 -5
- data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -9
- data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -10
- data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -10
- data/lib/sorcery/adapters/active_record_adapter.rb +120 -0
- data/lib/sorcery/adapters/base_adapter.rb +30 -0
- data/lib/sorcery/adapters/data_mapper_adapter.rb +176 -0
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +110 -0
- data/lib/sorcery/adapters/mongoid_adapter.rb +97 -0
- data/lib/sorcery/controller/config.rb +65 -0
- data/lib/sorcery/controller/submodules/activity_logging.rb +27 -21
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
- data/lib/sorcery/controller/submodules/external.rb +107 -75
- data/lib/sorcery/controller/submodules/remember_me.rb +5 -5
- data/lib/sorcery/controller/submodules/session_timeout.rb +11 -7
- data/lib/sorcery/controller.rb +27 -76
- data/lib/sorcery/model/config.rb +96 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +32 -12
- data/lib/sorcery/model/submodules/brute_force_protection.rb +36 -36
- data/lib/sorcery/model/submodules/external.rb +53 -9
- data/lib/sorcery/model/submodules/remember_me.rb +15 -19
- data/lib/sorcery/model/submodules/reset_password.rb +36 -33
- data/lib/sorcery/model/submodules/user_activation.rb +51 -48
- data/lib/sorcery/model/temporary_token.rb +4 -4
- data/lib/sorcery/model.rb +85 -175
- data/lib/sorcery/protocols/oauth.rb +42 -0
- data/lib/sorcery/protocols/oauth2.rb +47 -0
- data/lib/sorcery/providers/base.rb +38 -0
- data/lib/sorcery/providers/facebook.rb +74 -0
- data/lib/sorcery/providers/github.rb +60 -0
- data/lib/sorcery/providers/google.rb +51 -0
- data/lib/sorcery/providers/heroku.rb +57 -0
- data/lib/sorcery/providers/jira.rb +77 -0
- data/lib/sorcery/providers/linkedin.rb +66 -0
- data/lib/sorcery/providers/liveid.rb +53 -0
- data/lib/sorcery/providers/salesforce.rb +50 -0
- data/lib/sorcery/providers/twitter.rb +59 -0
- data/lib/sorcery/providers/vk.rb +63 -0
- data/lib/sorcery/providers/xing.rb +64 -0
- data/lib/sorcery/railties/tasks.rake +1 -7
- data/lib/sorcery/test_helpers/internal/rails.rb +17 -6
- data/lib/sorcery/test_helpers/internal.rb +27 -6
- data/lib/sorcery/test_helpers/rails/controller.rb +21 -0
- data/lib/sorcery/test_helpers/rails/integration.rb +26 -0
- data/lib/sorcery/version.rb +3 -0
- data/lib/sorcery.rb +83 -57
- data/sorcery.gemspec +24 -363
- data/spec/active_record/user_activation_spec.rb +18 -0
- data/spec/active_record/user_activity_logging_spec.rb +17 -0
- data/spec/{rails3/spec → active_record}/user_brute_force_protection_spec.rb +6 -5
- data/spec/{rails3/spec → active_record}/user_oauth_spec.rb +6 -5
- data/spec/{rails3/spec → active_record}/user_remember_me_spec.rb +5 -4
- data/spec/{rails3/spec → active_record}/user_reset_password_spec.rb +7 -7
- data/spec/active_record/user_spec.rb +37 -0
- data/spec/controllers/controller_activity_logging_spec.rb +124 -0
- data/spec/controllers/controller_brute_force_protection_spec.rb +43 -0
- data/spec/controllers/controller_http_basic_auth_spec.rb +68 -0
- data/spec/controllers/controller_oauth2_spec.rb +429 -0
- data/spec/controllers/controller_oauth_spec.rb +240 -0
- data/spec/controllers/controller_remember_me_spec.rb +117 -0
- data/spec/controllers/controller_session_timeout_spec.rb +80 -0
- data/spec/controllers/controller_spec.rb +218 -0
- data/spec/data_mapper/user_activation_spec.rb +10 -0
- data/spec/data_mapper/user_activity_logging_spec.rb +14 -0
- data/spec/data_mapper/user_brute_force_protection_spec.rb +9 -0
- data/spec/data_mapper/user_oauth_spec.rb +9 -0
- data/spec/data_mapper/user_remember_me_spec.rb +8 -0
- data/spec/data_mapper/user_reset_password_spec.rb +8 -0
- data/spec/data_mapper/user_spec.rb +27 -0
- data/spec/mongo_mapper/user_activation_spec.rb +9 -0
- data/spec/mongo_mapper/user_activity_logging_spec.rb +8 -0
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +8 -0
- data/spec/mongo_mapper/user_oauth_spec.rb +8 -0
- data/spec/mongo_mapper/user_remember_me_spec.rb +8 -0
- data/spec/mongo_mapper/user_reset_password_spec.rb +8 -0
- data/spec/mongo_mapper/user_spec.rb +37 -0
- data/spec/mongoid/user_activation_spec.rb +9 -0
- data/spec/mongoid/user_activity_logging_spec.rb +8 -0
- data/spec/mongoid/user_brute_force_protection_spec.rb +8 -0
- data/spec/mongoid/user_oauth_spec.rb +8 -0
- data/spec/mongoid/user_remember_me_spec.rb +8 -0
- data/spec/mongoid/user_reset_password_spec.rb +8 -0
- data/spec/mongoid/user_spec.rb +51 -0
- data/spec/orm/active_record.rb +21 -0
- data/spec/orm/data_mapper.rb +48 -0
- data/spec/orm/mongo_mapper.rb +10 -0
- data/spec/orm/mongoid.rb +22 -0
- data/spec/{rails3/app/models → rails_app/app/active_record}/user.rb +1 -2
- data/spec/rails_app/app/active_record/user_provider.rb +3 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +285 -0
- data/spec/rails_app/app/data_mapper/authentication.rb +8 -0
- data/spec/rails_app/app/data_mapper/user.rb +7 -0
- data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/user.rb +2 -0
- data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/user.rb +2 -0
- data/spec/rails_app/app/views/sorcery_mailer/send_unlock_token_email.text.erb +1 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config/application.rb +13 -8
- data/spec/rails_app/config/boot.rb +4 -0
- data/spec/rails_app/config/database.yml +22 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config/environments/test.rb +2 -0
- data/spec/{rails3_mongoid → rails_app}/config/initializers/session_store.rb +4 -0
- data/spec/rails_app/config/routes.rb +51 -0
- data/spec/{rails3_mongo_mapper → rails_app}/config.ru +1 -1
- data/spec/{rails3 → rails_app}/db/migrate/activation/20101224223622_add_activation_to_users.rb +3 -3
- data/spec/{rails3 → rails_app}/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +2 -0
- data/spec/{rails3 → rails_app}/db/migrate/core/20101224223620_create_users.rb +2 -2
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +22 -0
- data/spec/rails_app/log/development.log +1791 -0
- data/spec/shared_examples/user_activation_shared_examples.rb +137 -98
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +86 -13
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +140 -21
- data/spec/shared_examples/user_oauth_shared_examples.rb +21 -16
- data/spec/shared_examples/user_remember_me_shared_examples.rb +36 -24
- data/spec/shared_examples/user_reset_password_shared_examples.rb +163 -130
- data/spec/shared_examples/user_shared_examples.rb +370 -195
- data/spec/sorcery_crypto_providers_spec.rb +74 -72
- data/spec/spec_helper.rb +32 -4
- metadata +259 -425
- data/Gemfile.lock +0 -192
- data/README.rdoc +0 -261
- data/VERSION +0 -1
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -35
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -45
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -97
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -91
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -90
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -101
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -91
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -99
- data/lib/sorcery/model/adapters/active_record.rb +0 -49
- data/lib/sorcery/model/adapters/mongo_mapper.rb +0 -56
- data/lib/sorcery/model/adapters/mongoid.rb +0 -88
- data/lib/sorcery/test_helpers/rails.rb +0 -16
- data/lib/sorcery/test_helpers.rb +0 -5
- data/spec/Gemfile +0 -12
- data/spec/Gemfile.lock +0 -129
- data/spec/README.md +0 -31
- data/spec/Rakefile +0 -12
- data/spec/rails3/.gitignore +0 -4
- data/spec/rails3/.rspec +0 -1
- data/spec/rails3/Gemfile +0 -15
- data/spec/rails3/Gemfile.lock +0 -162
- data/spec/rails3/README +0 -256
- data/spec/rails3/Rakefile +0 -11
- data/spec/rails3/app/controllers/application_controller.rb +0 -208
- data/spec/rails3/app/views/sorcery_mailer/send_unlock_token_email.text.erb +0 -1
- data/spec/rails3/config/application.rb +0 -46
- data/spec/rails3/config/boot.rb +0 -13
- data/spec/rails3/config/database.yml +0 -27
- data/spec/rails3/config/environments/development.rb +0 -26
- data/spec/rails3/config/environments/in_memory.rb +0 -35
- data/spec/rails3/config/environments/production.rb +0 -49
- data/spec/rails3/config/environments/test.rb +0 -35
- data/spec/rails3/config/initializers/session_store.rb +0 -8
- data/spec/rails3/config/routes.rb +0 -59
- data/spec/rails3/config.ru +0 -4
- data/spec/rails3/db/migrate/external/20101224223628_create_authentications.rb +0 -14
- data/spec/rails3/lib/tasks/.gitkeep +0 -0
- data/spec/rails3/public/404.html +0 -26
- data/spec/rails3/public/422.html +0 -26
- data/spec/rails3/public/500.html +0 -26
- data/spec/rails3/public/favicon.ico +0 -0
- data/spec/rails3/public/images/rails.png +0 -0
- data/spec/rails3/public/javascripts/application.js +0 -2
- data/spec/rails3/public/javascripts/controls.js +0 -965
- data/spec/rails3/public/javascripts/dragdrop.js +0 -974
- data/spec/rails3/public/javascripts/effects.js +0 -1123
- data/spec/rails3/public/javascripts/prototype.js +0 -6001
- data/spec/rails3/public/javascripts/rails.js +0 -175
- data/spec/rails3/public/robots.txt +0 -5
- data/spec/rails3/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3/script/rails +0 -6
- data/spec/rails3/spec/controller_activity_logging_spec.rb +0 -115
- data/spec/rails3/spec/controller_brute_force_protection_spec.rb +0 -88
- data/spec/rails3/spec/controller_http_basic_auth_spec.rb +0 -50
- data/spec/rails3/spec/controller_oauth2_spec.rb +0 -380
- data/spec/rails3/spec/controller_oauth_spec.rb +0 -206
- data/spec/rails3/spec/controller_remember_me_spec.rb +0 -96
- data/spec/rails3/spec/controller_session_timeout_spec.rb +0 -55
- data/spec/rails3/spec/controller_spec.rb +0 -177
- data/spec/rails3/spec/integration_spec.rb +0 -23
- data/spec/rails3/spec/spec.opts +0 -2
- data/spec/rails3/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3/spec/spec_helper.rb +0 -71
- data/spec/rails3/spec/user_activation_spec.rb +0 -16
- data/spec/rails3/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3/spec/user_spec.rb +0 -36
- data/spec/rails3/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/.gitignore +0 -4
- data/spec/rails3_mongo_mapper/.rspec +0 -1
- data/spec/rails3_mongo_mapper/Gemfile +0 -16
- data/spec/rails3_mongo_mapper/Gemfile.lock +0 -156
- data/spec/rails3_mongo_mapper/Rakefile +0 -11
- data/spec/rails3_mongo_mapper/app/controllers/application_controller.rb +0 -122
- data/spec/rails3_mongo_mapper/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_mongo_mapper/app/mailers/sorcery_mailer.rb +0 -25
- data/spec/rails3_mongo_mapper/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.html.erb +0 -17
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_email.text.erb +0 -9
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
- data/spec/rails3_mongo_mapper/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
- data/spec/rails3_mongo_mapper/config/boot.rb +0 -13
- data/spec/rails3_mongo_mapper/config/environment.rb +0 -5
- data/spec/rails3_mongo_mapper/config/environments/development.rb +0 -30
- data/spec/rails3_mongo_mapper/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongo_mapper/config/environments/production.rb +0 -49
- data/spec/rails3_mongo_mapper/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_mongo_mapper/config/initializers/inflections.rb +0 -10
- data/spec/rails3_mongo_mapper/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_mongo_mapper/config/initializers/mongo.rb +0 -2
- data/spec/rails3_mongo_mapper/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_mongo_mapper/config/initializers/session_store.rb +0 -8
- data/spec/rails3_mongo_mapper/config/locales/en.yml +0 -5
- data/spec/rails3_mongo_mapper/config/routes.rb +0 -59
- data/spec/rails3_mongo_mapper/db/schema.rb +0 -23
- data/spec/rails3_mongo_mapper/db/seeds.rb +0 -7
- data/spec/rails3_mongo_mapper/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/public/404.html +0 -26
- data/spec/rails3_mongo_mapper/public/422.html +0 -26
- data/spec/rails3_mongo_mapper/public/500.html +0 -26
- 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 +0 -2
- data/spec/rails3_mongo_mapper/public/javascripts/controls.js +0 -965
- data/spec/rails3_mongo_mapper/public/javascripts/dragdrop.js +0 -974
- data/spec/rails3_mongo_mapper/public/javascripts/effects.js +0 -1123
- data/spec/rails3_mongo_mapper/public/javascripts/prototype.js +0 -6001
- data/spec/rails3_mongo_mapper/public/javascripts/rails.js +0 -175
- data/spec/rails3_mongo_mapper/public/robots.txt +0 -5
- data/spec/rails3_mongo_mapper/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongo_mapper/script/rails +0 -6
- data/spec/rails3_mongo_mapper/spec/controller_spec.rb +0 -170
- data/spec/rails3_mongo_mapper/spec/spec.opts +0 -2
- data/spec/rails3_mongo_mapper/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3_mongo_mapper/spec/spec_helper.rb +0 -55
- data/spec/rails3_mongo_mapper/spec/user_activation_spec.rb +0 -9
- data/spec/rails3_mongo_mapper/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_brute_force_protection_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_oauth_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_remember_me_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_reset_password_spec.rb +0 -8
- data/spec/rails3_mongo_mapper/spec/user_spec.rb +0 -37
- data/spec/rails3_mongo_mapper/vendor/plugins/.gitkeep +0 -0
- data/spec/rails3_mongoid/.gitignore +0 -4
- data/spec/rails3_mongoid/.rspec +0 -1
- data/spec/rails3_mongoid/Gemfile +0 -15
- data/spec/rails3_mongoid/Gemfile.lock +0 -146
- data/spec/rails3_mongoid/Rakefile +0 -11
- data/spec/rails3_mongoid/app/controllers/application_controller.rb +0 -127
- data/spec/rails3_mongoid/app/helpers/application_helper.rb +0 -2
- data/spec/rails3_mongoid/app/mailers/sorcery_mailer.rb +0 -25
- data/spec/rails3_mongoid/app/views/layouts/application.html.erb +0 -14
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.html.erb +0 -17
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_email.text.erb +0 -9
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.html.erb +0 -17
- data/spec/rails3_mongoid/app/views/sorcery_mailer/activation_success_email.text.erb +0 -9
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.html.erb +0 -16
- data/spec/rails3_mongoid/app/views/sorcery_mailer/reset_password_email.text.erb +0 -8
- data/spec/rails3_mongoid/config/application.rb +0 -51
- data/spec/rails3_mongoid/config/boot.rb +0 -13
- data/spec/rails3_mongoid/config/environment.rb +0 -5
- data/spec/rails3_mongoid/config/environments/development.rb +0 -26
- data/spec/rails3_mongoid/config/environments/in_memory.rb +0 -0
- data/spec/rails3_mongoid/config/environments/production.rb +0 -49
- data/spec/rails3_mongoid/config/environments/test.rb +0 -35
- data/spec/rails3_mongoid/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails3_mongoid/config/initializers/inflections.rb +0 -10
- data/spec/rails3_mongoid/config/initializers/mime_types.rb +0 -5
- data/spec/rails3_mongoid/config/initializers/secret_token.rb +0 -7
- data/spec/rails3_mongoid/config/locales/en.yml +0 -5
- data/spec/rails3_mongoid/config/mongoid.yml +0 -7
- data/spec/rails3_mongoid/config/routes.rb +0 -59
- data/spec/rails3_mongoid/config.ru +0 -4
- data/spec/rails3_mongoid/db/schema.rb +0 -23
- data/spec/rails3_mongoid/db/seeds.rb +0 -7
- data/spec/rails3_mongoid/lib/tasks/.gitkeep +0 -0
- data/spec/rails3_mongoid/public/404.html +0 -26
- data/spec/rails3_mongoid/public/422.html +0 -26
- data/spec/rails3_mongoid/public/500.html +0 -26
- data/spec/rails3_mongoid/public/favicon.ico +0 -0
- data/spec/rails3_mongoid/public/images/rails.png +0 -0
- data/spec/rails3_mongoid/public/javascripts/application.js +0 -2
- data/spec/rails3_mongoid/public/javascripts/controls.js +0 -965
- data/spec/rails3_mongoid/public/javascripts/dragdrop.js +0 -974
- data/spec/rails3_mongoid/public/javascripts/effects.js +0 -1123
- data/spec/rails3_mongoid/public/javascripts/prototype.js +0 -6001
- data/spec/rails3_mongoid/public/javascripts/rails.js +0 -175
- data/spec/rails3_mongoid/public/robots.txt +0 -5
- data/spec/rails3_mongoid/public/stylesheets/.gitkeep +0 -0
- data/spec/rails3_mongoid/script/rails +0 -6
- data/spec/rails3_mongoid/spec/controller_activity_logging_spec.rb +0 -105
- data/spec/rails3_mongoid/spec/controller_spec.rb +0 -181
- data/spec/rails3_mongoid/spec/spec.opts +0 -2
- data/spec/rails3_mongoid/spec/spec_helper.orig.rb +0 -27
- data/spec/rails3_mongoid/spec/spec_helper.rb +0 -55
- data/spec/rails3_mongoid/spec/user_activation_spec.rb +0 -9
- data/spec/rails3_mongoid/spec/user_activity_logging_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_brute_force_protection_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_oauth_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_remember_me_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_reset_password_spec.rb +0 -8
- data/spec/rails3_mongoid/spec/user_spec.rb +0 -38
- data/spec/rails3_mongoid/vendor/plugins/.gitkeep +0 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -56
- data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -55
- /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
- /data/spec/{rails3/app/models → rails_app/app/active_record}/authentication.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/helpers/application_helper.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/mailers/sorcery_mailer.rb +0 -0
- /data/spec/{rails3_mongo_mapper/app/models → rails_app/app/mongo_mapper}/authentication.rb +0 -0
- /data/spec/{rails3_mongoid/app/models → rails_app/app/mongoid}/authentication.rb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/application/index.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/layouts/application.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_email.text.erb +0 -0
- /data/spec/{rails3/app/views/sorcery_mailer/activation_success_email.html.erb → rails_app/app/views/sorcery_mailer/activation_needed_email.html.erb} +0 -0
- /data/spec/{rails3_mongo_mapper → rails_app}/app/views/sorcery_mailer/activation_success_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/activation_success_email.text.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.html.erb +0 -0
- /data/spec/{rails3 → rails_app}/app/views/sorcery_mailer/reset_password_email.text.erb +0 -0
- /data/spec/{rails3 → rails_app}/config/environment.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/backtrace_silencers.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/inflections.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/mime_types.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/initializers/secret_token.rb +0 -0
- /data/spec/{rails3 → rails_app}/config/locales/en.yml +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/schema.rb +0 -0
- /data/spec/{rails3 → rails_app}/db/seeds.rb +0 -0
data/lib/sorcery/model.rb
CHANGED
|
@@ -7,91 +7,70 @@ module Sorcery
|
|
|
7
7
|
# which when called adds the other capabilities to the class.
|
|
8
8
|
# This method is also the place to configure the plugin in the Model layer.
|
|
9
9
|
module Model
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
class << self
|
|
13
|
-
def authenticates_with_sorcery!
|
|
14
|
-
@sorcery_config = Config.new
|
|
15
|
-
self.class_eval do
|
|
16
|
-
extend ClassMethods # included here, before submodules, so they can be overriden by them.
|
|
17
|
-
include InstanceMethods
|
|
18
|
-
include TemporaryToken
|
|
19
|
-
end
|
|
10
|
+
def authenticates_with_sorcery!
|
|
11
|
+
@sorcery_config = Config.new
|
|
20
12
|
|
|
21
|
-
|
|
13
|
+
extend ClassMethods # included here, before submodules, so they can be overriden by them.
|
|
14
|
+
include InstanceMethods
|
|
15
|
+
include TemporaryToken
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
|
|
17
|
+
include_required_submodules!
|
|
25
18
|
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
# This runs the options block set in the initializer on the model class.
|
|
20
|
+
::Sorcery::Controller::Config.user_config.tap{|blk| blk.call(@sorcery_config) if blk}
|
|
28
21
|
|
|
29
|
-
|
|
22
|
+
define_base_fields
|
|
23
|
+
init_orm_hooks!
|
|
30
24
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
@sorcery_config.after_config << :add_config_inheritance if @sorcery_config.subclasses_inherit_config
|
|
26
|
+
@sorcery_config.after_config.each { |c| send(c) }
|
|
27
|
+
end
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
# includes required submodules into the model class,
|
|
38
|
-
# which usually is called User.
|
|
39
|
-
def include_required_submodules!
|
|
40
|
-
self.class_eval do
|
|
41
|
-
@sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
|
|
42
|
-
@sorcery_config.submodules.each do |mod|
|
|
43
|
-
begin
|
|
44
|
-
include Submodules.const_get(mod.to_s.split("_").map {|p| p.capitalize}.join(""))
|
|
45
|
-
rescue NameError
|
|
46
|
-
# don't stop on a missing submodule. Needed because some submodules are only defined
|
|
47
|
-
# in the controller side.
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
29
|
+
private
|
|
52
30
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end
|
|
31
|
+
def define_base_fields
|
|
32
|
+
self.class_eval do
|
|
33
|
+
sorcery_config.username_attribute_names.each do |username|
|
|
34
|
+
sorcery_adapter.define_field username, String, length: 255
|
|
35
|
+
end
|
|
36
|
+
unless sorcery_config.username_attribute_names.include?(sorcery_config.email_attribute_name)
|
|
37
|
+
sorcery_adapter.define_field sorcery_config.email_attribute_name, String, length: 255
|
|
38
|
+
end
|
|
39
|
+
sorcery_adapter.define_field sorcery_config.crypted_password_attribute_name, String, length: 255
|
|
40
|
+
sorcery_adapter.define_field sorcery_config.salt_attribute_name, String, length: 255
|
|
41
|
+
end
|
|
65
42
|
|
|
66
|
-
|
|
67
|
-
def init_mongo_mapper_support!
|
|
68
|
-
self.class_eval do
|
|
69
|
-
sorcery_config.username_attribute_names.each do |username|
|
|
70
|
-
key username, String
|
|
71
|
-
end
|
|
72
|
-
key sorcery_config.email_attribute_name, String unless sorcery_config.username_attribute_names.include?(sorcery_config.email_attribute_name)
|
|
73
|
-
key sorcery_config.crypted_password_attribute_name, String
|
|
74
|
-
key sorcery_config.salt_attribute_name, String
|
|
75
|
-
end
|
|
76
|
-
end
|
|
43
|
+
end
|
|
77
44
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
end
|
|
45
|
+
# includes required submodules into the model class,
|
|
46
|
+
# which usually is called User.
|
|
47
|
+
def include_required_submodules!
|
|
48
|
+
self.class_eval do
|
|
49
|
+
@sorcery_config.submodules = ::Sorcery::Controller::Config.submodules
|
|
50
|
+
@sorcery_config.submodules.each do |mod|
|
|
51
|
+
begin
|
|
52
|
+
include Submodules.const_get(mod.to_s.split('_').map {|p| p.capitalize}.join)
|
|
53
|
+
rescue NameError
|
|
54
|
+
# don't stop on a missing submodule. Needed because some submodules are only defined
|
|
55
|
+
# in the controller side.
|
|
90
56
|
end
|
|
91
57
|
end
|
|
92
58
|
end
|
|
93
59
|
end
|
|
94
60
|
|
|
61
|
+
# add virtual password accessor and ORM callbacks.
|
|
62
|
+
def init_orm_hooks!
|
|
63
|
+
sorcery_adapter.define_callback :before, :validation, :encrypt_password, if: Proc.new {|record|
|
|
64
|
+
record.send(sorcery_config.password_attribute_name).present?
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
sorcery_adapter.define_callback :after, :save, :clear_virtual_password, if: Proc.new {|record|
|
|
68
|
+
record.send(sorcery_config.password_attribute_name).present?
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
attr_accessor sorcery_config.password_attribute_name
|
|
72
|
+
end
|
|
73
|
+
|
|
95
74
|
module ClassMethods
|
|
96
75
|
# Returns the class instance variable for configuration, when called by the class itself.
|
|
97
76
|
def sorcery_config
|
|
@@ -104,13 +83,22 @@ module Sorcery
|
|
|
104
83
|
# returns the user if success, nil otherwise.
|
|
105
84
|
def authenticate(*credentials)
|
|
106
85
|
raise ArgumentError, "at least 2 arguments required" if credentials.size < 2
|
|
107
|
-
credentials[0].downcase! if @sorcery_config.downcase_username_before_authenticating
|
|
108
|
-
user = find_by_credentials(credentials)
|
|
109
86
|
|
|
110
|
-
|
|
87
|
+
return false if credentials[0].blank?
|
|
88
|
+
|
|
89
|
+
if @sorcery_config.downcase_username_before_authenticating
|
|
90
|
+
credentials[0].downcase!
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
user = sorcery_adapter.find_by_credentials(credentials)
|
|
94
|
+
|
|
95
|
+
if user.respond_to?(:active_for_authentication?)
|
|
96
|
+
return nil if !user.active_for_authentication?
|
|
97
|
+
end
|
|
111
98
|
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
set_encryption_attributes
|
|
100
|
+
|
|
101
|
+
user if user && @sorcery_config.before_authenticate.all? {|c| user.send(c)} && user.valid_password?(credentials[1])
|
|
114
102
|
end
|
|
115
103
|
|
|
116
104
|
# encrypt tokens using current encryption_provider.
|
|
@@ -129,13 +117,7 @@ module Sorcery
|
|
|
129
117
|
@sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
|
|
130
118
|
@sorcery_config.encryption_provider.join_token = @sorcery_config.salt_join_token if @sorcery_config.encryption_provider.respond_to?(:join_token) && @sorcery_config.salt_join_token
|
|
131
119
|
end
|
|
132
|
-
|
|
133
|
-
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
|
134
|
-
def credentials_match?(crypted, *tokens)
|
|
135
|
-
return crypted == tokens.join if @sorcery_config.encryption_provider.nil?
|
|
136
|
-
@sorcery_config.encryption_provider.matches?(crypted, *tokens)
|
|
137
|
-
end
|
|
138
|
-
|
|
120
|
+
|
|
139
121
|
def add_config_inheritance
|
|
140
122
|
self.class_eval do
|
|
141
123
|
def self.inherited(subclass)
|
|
@@ -164,6 +146,16 @@ module Sorcery
|
|
|
164
146
|
send(sorcery_config.crypted_password_attribute_name).nil?
|
|
165
147
|
end
|
|
166
148
|
|
|
149
|
+
# Calls the configured encryption provider to compare the supplied password with the encrypted one.
|
|
150
|
+
def valid_password?(pass)
|
|
151
|
+
_crypted = self.send(sorcery_config.crypted_password_attribute_name)
|
|
152
|
+
return _crypted == pass if sorcery_config.encryption_provider.nil?
|
|
153
|
+
|
|
154
|
+
_salt = self.send(sorcery_config.salt_attribute_name) unless sorcery_config.salt_attribute_name.nil?
|
|
155
|
+
|
|
156
|
+
sorcery_config.encryption_provider.matches?(_crypted, pass, _salt)
|
|
157
|
+
end
|
|
158
|
+
|
|
167
159
|
protected
|
|
168
160
|
|
|
169
161
|
# creates new salt and saves it.
|
|
@@ -177,6 +169,10 @@ module Sorcery
|
|
|
177
169
|
def clear_virtual_password
|
|
178
170
|
config = sorcery_config
|
|
179
171
|
self.send(:"#{config.password_attribute_name}=", nil)
|
|
172
|
+
|
|
173
|
+
if respond_to?(:"#{config.password_attribute_name}_confirmation=")
|
|
174
|
+
self.send(:"#{config.password_attribute_name}_confirmation=", nil)
|
|
175
|
+
end
|
|
180
176
|
end
|
|
181
177
|
|
|
182
178
|
# calls the requested email method on the configured mailer
|
|
@@ -185,100 +181,14 @@ module Sorcery
|
|
|
185
181
|
config = sorcery_config
|
|
186
182
|
mail = config.send(mailer).send(config.send(method),self)
|
|
187
183
|
if defined?(ActionMailer) and config.send(mailer).kind_of?(Class) and config.send(mailer) < ActionMailer::Base
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
# Every submodule which gets loaded may add accessors to this class so that all
|
|
195
|
-
# options will be configured from a single place.
|
|
196
|
-
class Config
|
|
197
|
-
|
|
198
|
-
attr_accessor :username_attribute_names, # change default username attribute, for example, to use :email
|
|
199
|
-
# as the login.
|
|
200
|
-
|
|
201
|
-
:password_attribute_name, # change *virtual* password attribute, the one which is used
|
|
202
|
-
# until an encrypted one is generated.
|
|
203
|
-
|
|
204
|
-
:email_attribute_name, # change default email attribute.
|
|
205
|
-
|
|
206
|
-
:downcase_username_before_authenticating, # downcase the username before trying to authenticate, default is false
|
|
207
|
-
|
|
208
|
-
:crypted_password_attribute_name, # change default crypted_password attribute.
|
|
209
|
-
:salt_join_token, # what pattern to use to join the password with the salt
|
|
210
|
-
:salt_attribute_name, # change default salt attribute.
|
|
211
|
-
:stretches, # how many times to apply encryption to the password.
|
|
212
|
-
:encryption_key, # encryption key used to encrypt reversible encryptions such as
|
|
213
|
-
# AES256.
|
|
214
|
-
|
|
215
|
-
:subclasses_inherit_config, # make this configuration inheritable for subclasses. Useful for
|
|
216
|
-
# ActiveRecord's STI.
|
|
217
|
-
|
|
218
|
-
:submodules, # configured in config/application.rb
|
|
219
|
-
:before_authenticate, # an array of method names to call before authentication
|
|
220
|
-
# completes. used internally.
|
|
221
|
-
|
|
222
|
-
:after_config # an array of method names to call after configuration by user.
|
|
223
|
-
# used internally.
|
|
224
|
-
|
|
225
|
-
attr_reader :encryption_provider, # change default encryption_provider.
|
|
226
|
-
:custom_encryption_provider, # use an external encryption class.
|
|
227
|
-
:encryption_algorithm # encryption algorithm name. See 'encryption_algorithm=' below
|
|
228
|
-
# for available options.
|
|
229
|
-
|
|
230
|
-
def initialize
|
|
231
|
-
@defaults = {
|
|
232
|
-
:@submodules => [],
|
|
233
|
-
:@username_attribute_names => [:username],
|
|
234
|
-
:@password_attribute_name => :password,
|
|
235
|
-
:@downcase_username_before_authenticating => false,
|
|
236
|
-
:@email_attribute_name => :email,
|
|
237
|
-
:@crypted_password_attribute_name => :crypted_password,
|
|
238
|
-
:@encryption_algorithm => :bcrypt,
|
|
239
|
-
:@encryption_provider => CryptoProviders::BCrypt,
|
|
240
|
-
:@custom_encryption_provider => nil,
|
|
241
|
-
:@encryption_key => nil,
|
|
242
|
-
:@salt_join_token => "",
|
|
243
|
-
:@salt_attribute_name => :salt,
|
|
244
|
-
:@stretches => nil,
|
|
245
|
-
:@subclasses_inherit_config => false,
|
|
246
|
-
:@before_authenticate => [],
|
|
247
|
-
:@after_config => []
|
|
248
|
-
}
|
|
249
|
-
reset!
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
# Resets all configuration options to their default values.
|
|
253
|
-
def reset!
|
|
254
|
-
@defaults.each do |k,v|
|
|
255
|
-
instance_variable_set(k,v)
|
|
256
|
-
end
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
def username_attribute_names=(fields)
|
|
260
|
-
@username_attribute_names = fields.kind_of?(Array) ? fields : [fields]
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def custom_encryption_provider=(provider)
|
|
264
|
-
@custom_encryption_provider = @encryption_provider = provider
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
def encryption_algorithm=(algo)
|
|
268
|
-
@encryption_algorithm = algo
|
|
269
|
-
@encryption_provider = case @encryption_algorithm.to_sym
|
|
270
|
-
when :none then nil
|
|
271
|
-
when :md5 then CryptoProviders::MD5
|
|
272
|
-
when :sha1 then CryptoProviders::SHA1
|
|
273
|
-
when :sha256 then CryptoProviders::SHA256
|
|
274
|
-
when :sha512 then CryptoProviders::SHA512
|
|
275
|
-
when :aes256 then CryptoProviders::AES256
|
|
276
|
-
when :bcrypt then CryptoProviders::BCrypt
|
|
277
|
-
when :custom then @custom_encryption_provider
|
|
278
|
-
else raise ArgumentError.new("Encryption algorithm supplied, #{algo}, is invalid")
|
|
184
|
+
# Rails 4.2 deprecates #deliver
|
|
185
|
+
if mail.respond_to?(:deliver_now)
|
|
186
|
+
mail.deliver_now
|
|
187
|
+
else
|
|
188
|
+
mail.deliver
|
|
189
|
+
end
|
|
279
190
|
end
|
|
280
191
|
end
|
|
281
|
-
|
|
282
192
|
end
|
|
283
193
|
|
|
284
194
|
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'oauth'
|
|
2
|
+
|
|
3
|
+
module Sorcery
|
|
4
|
+
module Protocols
|
|
5
|
+
module Oauth
|
|
6
|
+
|
|
7
|
+
def oauth_version
|
|
8
|
+
'1.0'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def get_request_token(token=nil,secret=nil)
|
|
12
|
+
return ::OAuth::RequestToken.new(get_consumer, token, secret) if token && secret
|
|
13
|
+
get_consumer.get_request_token(oauth_callback: @callback_url)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def authorize_url(args)
|
|
17
|
+
get_request_token(
|
|
18
|
+
args[:request_token],
|
|
19
|
+
args[:request_token_secret]
|
|
20
|
+
).authorize_url({
|
|
21
|
+
oauth_callback: @callback_url
|
|
22
|
+
})
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_access_token(args)
|
|
26
|
+
get_request_token(
|
|
27
|
+
args[:request_token],
|
|
28
|
+
args[:request_token_secret]
|
|
29
|
+
).get_access_token({
|
|
30
|
+
oauth_verifier: args[:oauth_verifier]
|
|
31
|
+
})
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
|
|
36
|
+
def get_consumer
|
|
37
|
+
::OAuth::Consumer.new(@key, @secret, site: @site)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'oauth2'
|
|
2
|
+
|
|
3
|
+
module Sorcery
|
|
4
|
+
module Protocols
|
|
5
|
+
module Oauth2
|
|
6
|
+
|
|
7
|
+
def oauth_version
|
|
8
|
+
'2.0'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def authorize_url(options = {})
|
|
12
|
+
client = build_client(options)
|
|
13
|
+
client.auth_code.authorize_url(
|
|
14
|
+
redirect_uri: @callback_url,
|
|
15
|
+
scope: @scope,
|
|
16
|
+
display: @display,
|
|
17
|
+
state: @state
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def get_access_token(args, options = {})
|
|
22
|
+
client = build_client(options)
|
|
23
|
+
client.auth_code.get_token(
|
|
24
|
+
args[:code],
|
|
25
|
+
{
|
|
26
|
+
redirect_uri: @callback_url,
|
|
27
|
+
parse: options.delete(:parse)
|
|
28
|
+
},
|
|
29
|
+
options
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_client(options = {})
|
|
34
|
+
defaults = {
|
|
35
|
+
site: @site,
|
|
36
|
+
ssl: { ca_file: Sorcery::Controller::Config.ca_file }
|
|
37
|
+
}
|
|
38
|
+
::OAuth2::Client.new(
|
|
39
|
+
@key,
|
|
40
|
+
@secret,
|
|
41
|
+
defaults.merge!(options)
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module Providers
|
|
3
|
+
class Base
|
|
4
|
+
|
|
5
|
+
attr_reader :access_token
|
|
6
|
+
|
|
7
|
+
attr_accessor :callback_url, :key, :original_callback_url, :secret,
|
|
8
|
+
:site, :state, :user_info_mapping
|
|
9
|
+
|
|
10
|
+
def has_callback?; true; end
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@user_info_mapping = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def auth_hash(access_token, hash={})
|
|
17
|
+
return hash if access_token.nil?
|
|
18
|
+
|
|
19
|
+
token_hash = hash.dup
|
|
20
|
+
token_hash[:token] = access_token.token if access_token.respond_to?(:token)
|
|
21
|
+
token_hash[:refresh_token] = access_token.refresh_token if access_token.respond_to?(:refresh_token)
|
|
22
|
+
token_hash[:expires_at] = access_token.expires_at if access_token.respond_to?(:expires_at)
|
|
23
|
+
token_hash[:expires_in] = access_token.expires_at if access_token.respond_to?(:expires_in)
|
|
24
|
+
token_hash
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.name
|
|
28
|
+
super.gsub(/Sorcery::Providers::/, '').downcase
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Ensure that all descendant classes are loaded before run this
|
|
32
|
+
def self.descendants
|
|
33
|
+
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module Providers
|
|
3
|
+
# This class adds support for OAuth with facebook.com.
|
|
4
|
+
#
|
|
5
|
+
# config.facebook.key = <key>
|
|
6
|
+
# config.facebook.secret = <secret>
|
|
7
|
+
# ...
|
|
8
|
+
#
|
|
9
|
+
class Facebook < Base
|
|
10
|
+
|
|
11
|
+
include Protocols::Oauth2
|
|
12
|
+
|
|
13
|
+
attr_reader :mode, :param_name, :parse
|
|
14
|
+
attr_accessor :access_permissions, :display, :scope, :token_url,
|
|
15
|
+
:user_info_path, :auth_path, :api_version
|
|
16
|
+
|
|
17
|
+
def initialize
|
|
18
|
+
super
|
|
19
|
+
|
|
20
|
+
@site = 'https://graph.facebook.com'
|
|
21
|
+
@auth_site = 'https://www.facebook.com'
|
|
22
|
+
@user_info_path = 'me'
|
|
23
|
+
@scope = 'email'
|
|
24
|
+
@display = 'page'
|
|
25
|
+
@token_url = 'oauth/access_token'
|
|
26
|
+
@auth_path = 'dialog/oauth'
|
|
27
|
+
@mode = :query
|
|
28
|
+
@parse = :query
|
|
29
|
+
@param_name = 'access_token'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_user_hash(access_token)
|
|
33
|
+
response = access_token.get(user_info_path)
|
|
34
|
+
|
|
35
|
+
auth_hash(access_token).tap do |h|
|
|
36
|
+
h[:user_info] = JSON.parse(response.body)
|
|
37
|
+
h[:uid] = h[:user_info]['id']
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# calculates and returns the url to which the user should be redirected,
|
|
42
|
+
# to get authenticated at the external provider's site.
|
|
43
|
+
def login_url(params, session)
|
|
44
|
+
authorize_url
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# overrides oauth2#authorize_url to allow customized scope.
|
|
48
|
+
def authorize_url
|
|
49
|
+
|
|
50
|
+
# Fix: replace default oauth2 options, specially to prevent the Faraday gem which
|
|
51
|
+
# concatenates with "/", removing the Facebook api version
|
|
52
|
+
options = {
|
|
53
|
+
site: File::join(@site, api_version.to_s),
|
|
54
|
+
authorize_url: File::join(@auth_site, api_version.to_s, auth_path),
|
|
55
|
+
token_url: token_url
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@scope = access_permissions.present? ? access_permissions.join(',') : scope
|
|
59
|
+
super(options)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# tries to login the user from access token
|
|
63
|
+
def process_callback(params, session)
|
|
64
|
+
args = {}.tap do |a|
|
|
65
|
+
a[:code] = params[:code] if params[:code]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
get_access_token(args, token_url: token_url, mode: mode,
|
|
69
|
+
param_name: param_name, parse: parse)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module Providers
|
|
3
|
+
# This class adds support for OAuth with github.com.
|
|
4
|
+
#
|
|
5
|
+
# config.github.key = <key>
|
|
6
|
+
# config.github.secret = <secret>
|
|
7
|
+
# ...
|
|
8
|
+
#
|
|
9
|
+
class Github < Base
|
|
10
|
+
|
|
11
|
+
include Protocols::Oauth2
|
|
12
|
+
|
|
13
|
+
attr_accessor :auth_path, :scope, :token_url, :user_info_path
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@scope = nil
|
|
19
|
+
@site = 'https://github.com/'
|
|
20
|
+
@user_info_path = 'https://api.github.com/user'
|
|
21
|
+
@auth_path = '/login/oauth/authorize'
|
|
22
|
+
@token_url = '/login/oauth/access_token'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_user_hash(access_token)
|
|
26
|
+
response = access_token.get(user_info_path)
|
|
27
|
+
|
|
28
|
+
auth_hash(access_token).tap do |h|
|
|
29
|
+
h[:user_info] = JSON.parse(response.body).tap do |uih|
|
|
30
|
+
uih['email'] = primary_email(access_token) if scope =~ /user/
|
|
31
|
+
end
|
|
32
|
+
h[:uid] = h[:user_info]['id']
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# calculates and returns the url to which the user should be redirected,
|
|
37
|
+
# to get authenticated at the external provider's site.
|
|
38
|
+
def login_url(params, session)
|
|
39
|
+
authorize_url({ authorize_url: auth_path })
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# tries to login the user from access token
|
|
43
|
+
def process_callback(params, session)
|
|
44
|
+
args = {}.tap do |a|
|
|
45
|
+
a[:code] = params[:code] if params[:code]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
get_access_token(args, token_url: token_url, token_method: :post)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def primary_email(access_token)
|
|
52
|
+
response = access_token.get(user_info_path + "/emails")
|
|
53
|
+
emails = JSON.parse(response.body)
|
|
54
|
+
primary = emails.find{|i| i['primary'] }
|
|
55
|
+
primary && primary['email'] || emails.first && emails.first['email']
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Sorcery
|
|
2
|
+
module Providers
|
|
3
|
+
# This class adds support for OAuth with google.com.
|
|
4
|
+
#
|
|
5
|
+
# config.google.key = <key>
|
|
6
|
+
# config.google.secret = <secret>
|
|
7
|
+
# ...
|
|
8
|
+
#
|
|
9
|
+
class Google < Base
|
|
10
|
+
|
|
11
|
+
include Protocols::Oauth2
|
|
12
|
+
|
|
13
|
+
attr_accessor :auth_url, :scope, :token_url, :user_info_url
|
|
14
|
+
|
|
15
|
+
def initialize
|
|
16
|
+
super
|
|
17
|
+
|
|
18
|
+
@site = 'https://accounts.google.com'
|
|
19
|
+
@auth_url = '/o/oauth2/auth'
|
|
20
|
+
@token_url = '/o/oauth2/token'
|
|
21
|
+
@user_info_url = 'https://www.googleapis.com/oauth2/v1/userinfo'
|
|
22
|
+
@scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_user_hash(access_token)
|
|
26
|
+
response = access_token.get(user_info_url)
|
|
27
|
+
|
|
28
|
+
auth_hash(access_token).tap do |h|
|
|
29
|
+
h[:user_info] = JSON.parse(response.body)
|
|
30
|
+
h[:uid] = h[:user_info]['id']
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# calculates and returns the url to which the user should be redirected,
|
|
35
|
+
# to get authenticated at the external provider's site.
|
|
36
|
+
def login_url(params, session)
|
|
37
|
+
authorize_url({ authorize_url: auth_url })
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# tries to login the user from access token
|
|
41
|
+
def process_callback(params, session)
|
|
42
|
+
args = {}.tap do |a|
|
|
43
|
+
a[:code] = params[:code] if params[:code]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
get_access_token(args, token_url: token_url, token_method: :post)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|