sorcery 0.8.5 → 0.9.0
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 +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +122 -5
- data/CHANGELOG.md +37 -1
- data/Gemfile +10 -18
- data/README.md +159 -88
- 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/install_generator.rb +19 -5
- data/lib/generators/sorcery/templates/initializer.rb +34 -9
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +3 -1
- data/lib/generators/sorcery/templates/migration/core.rb +2 -2
- data/lib/generators/sorcery/templates/migration/external.rb +3 -1
- 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 +16 -21
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +6 -6
- data/lib/sorcery/controller/submodules/external.rb +35 -40
- data/lib/sorcery/controller/submodules/remember_me.rb +4 -4
- data/lib/sorcery/controller/submodules/session_timeout.rb +10 -6
- data/lib/sorcery/controller.rb +10 -74
- data/lib/sorcery/model/config.rb +96 -0
- data/lib/sorcery/model/submodules/activity_logging.rb +30 -13
- data/lib/sorcery/model/submodules/brute_force_protection.rb +21 -21
- 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 +33 -34
- data/lib/sorcery/model/submodules/user_activation.rb +36 -47
- data/lib/sorcery/model/temporary_token.rb +4 -4
- data/lib/sorcery/model.rb +73 -173
- 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 +63 -0
- data/lib/sorcery/providers/github.rb +51 -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/test_helpers/internal/rails.rb +14 -3
- data/lib/sorcery/test_helpers/internal.rb +7 -3
- 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 +82 -58
- data/sorcery.gemspec +19 -19
- data/spec/active_record/user_activation_spec.rb +1 -1
- data/spec/active_record/user_activity_logging_spec.rb +10 -1
- data/spec/active_record/user_brute_force_protection_spec.rb +1 -1
- data/spec/active_record/user_oauth_spec.rb +1 -1
- data/spec/active_record/user_remember_me_spec.rb +1 -1
- data/spec/active_record/user_reset_password_spec.rb +1 -1
- data/spec/active_record/user_spec.rb +7 -8
- 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 +414 -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 +1 -2
- data/spec/mongo_mapper/user_activity_logging_spec.rb +1 -1
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +1 -1
- data/spec/mongo_mapper/user_oauth_spec.rb +1 -1
- data/spec/mongo_mapper/user_remember_me_spec.rb +1 -1
- data/spec/mongo_mapper/user_reset_password_spec.rb +1 -1
- data/spec/mongo_mapper/user_spec.rb +7 -8
- data/spec/mongoid/user_activation_spec.rb +1 -2
- data/spec/mongoid/user_activity_logging_spec.rb +1 -2
- data/spec/mongoid/user_brute_force_protection_spec.rb +1 -2
- data/spec/mongoid/user_oauth_spec.rb +1 -2
- data/spec/mongoid/user_remember_me_spec.rb +1 -2
- data/spec/mongoid/user_reset_password_spec.rb +1 -2
- data/spec/mongoid/user_spec.rb +21 -9
- data/spec/orm/active_record.rb +14 -0
- data/spec/orm/data_mapper.rb +48 -0
- data/spec/orm/mongo_mapper.rb +1 -1
- data/spec/orm/mongoid.rb +5 -0
- data/spec/rails_app/app/controllers/sorcery_controller.rb +125 -59
- data/spec/rails_app/app/data_mapper/authentication.rb +8 -0
- data/spec/rails_app/app/data_mapper/user.rb +7 -0
- data/spec/rails_app/app/mongo_mapper/user.rb +2 -0
- data/spec/rails_app/config/routes.rb +27 -13
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +2 -2
- data/spec/shared_examples/user_activation_shared_examples.rb +108 -91
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +83 -15
- 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 +138 -117
- data/spec/shared_examples/user_shared_examples.rb +297 -150
- data/spec/sorcery_crypto_providers_spec.rb +28 -28
- data/spec/spec_helper.rb +12 -18
- metadata +99 -165
- data/Gemfile.rails4 +0 -24
- data/VERSION +0 -1
- data/lib/sorcery/controller/submodules/external/protocols/oauth1.rb +0 -46
- data/lib/sorcery/controller/submodules/external/protocols/oauth2.rb +0 -50
- data/lib/sorcery/controller/submodules/external/providers/base.rb +0 -21
- data/lib/sorcery/controller/submodules/external/providers/facebook.rb +0 -99
- data/lib/sorcery/controller/submodules/external/providers/github.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/google.rb +0 -92
- data/lib/sorcery/controller/submodules/external/providers/linkedin.rb +0 -103
- data/lib/sorcery/controller/submodules/external/providers/liveid.rb +0 -93
- data/lib/sorcery/controller/submodules/external/providers/twitter.rb +0 -94
- data/lib/sorcery/controller/submodules/external/providers/vk.rb +0 -101
- data/lib/sorcery/controller/submodules/external/providers/xing.rb +0 -98
- 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/active_record/controller_activity_logging_spec.rb +0 -140
- data/spec/active_record/controller_brute_force_protection_spec.rb +0 -136
- data/spec/active_record/controller_http_basic_auth_spec.rb +0 -59
- data/spec/active_record/controller_oauth2_spec.rb +0 -417
- data/spec/active_record/controller_oauth_spec.rb +0 -212
- data/spec/active_record/controller_remember_me_spec.rb +0 -96
- data/spec/active_record/controller_session_timeout_spec.rb +0 -55
- data/spec/active_record/controller_spec.rb +0 -182
- data/spec/active_record/integration_spec.rb +0 -23
- data/spec/mongo_mapper/controller_spec.rb +0 -175
- data/spec/mongoid/controller_activity_logging_spec.rb +0 -111
- data/spec/mongoid/controller_spec.rb +0 -186
- data/spec/rails_app/public/404.html +0 -26
- data/spec/rails_app/public/422.html +0 -26
- data/spec/rails_app/public/500.html +0 -26
- data/spec/rails_app/public/favicon.ico +0 -0
- data/spec/rails_app/public/images/rails.png +0 -0
- data/spec/rails_app/public/javascripts/application.js +0 -2
- data/spec/rails_app/public/javascripts/controls.js +0 -965
- data/spec/rails_app/public/javascripts/dragdrop.js +0 -974
- data/spec/rails_app/public/javascripts/effects.js +0 -1123
- data/spec/rails_app/public/javascripts/prototype.js +0 -6001
- data/spec/rails_app/public/javascripts/rails.js +0 -175
- data/spec/rails_app/public/robots.txt +0 -5
- data/spec/rails_app/public/stylesheets/.gitkeep +0 -0
- data/spec/shared_examples/controller_oauth2_shared_examples.rb +0 -56
- data/spec/shared_examples/controller_oauth_shared_examples.rb +0 -69
- /data/lib/sorcery/{controller/submodules/external/protocols → protocols}/certs/ca-bundle.crt +0 -0
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with facebook.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.facebook'.
|
|
8
|
-
# Via this new option you can configure Facebook specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.facebook.key = <key>
|
|
11
|
-
# config.facebook.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Facebook
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :facebook # access to facebook_client.
|
|
19
|
-
|
|
20
|
-
def merge_facebook_defaults!
|
|
21
|
-
@defaults.merge!(:@facebook => FacebookClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_facebook_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module FacebookClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:site,
|
|
36
|
-
:user_info_path,
|
|
37
|
-
:scope,
|
|
38
|
-
:user_info_mapping,
|
|
39
|
-
:display,
|
|
40
|
-
:access_permissions,
|
|
41
|
-
:state
|
|
42
|
-
attr_reader :access_token
|
|
43
|
-
|
|
44
|
-
include Protocols::Oauth2
|
|
45
|
-
|
|
46
|
-
def init
|
|
47
|
-
@site = "https://graph.facebook.com"
|
|
48
|
-
@user_info_path = "/me"
|
|
49
|
-
@scope = "email,offline_access"
|
|
50
|
-
@user_info_mapping = {}
|
|
51
|
-
@display = "page"
|
|
52
|
-
@token_url = "oauth/access_token"
|
|
53
|
-
@mode = :query
|
|
54
|
-
@parse = :query
|
|
55
|
-
@param_name = "access_token"
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def get_user_hash(access_token)
|
|
59
|
-
user_hash = {}
|
|
60
|
-
response = access_token.get(@user_info_path)
|
|
61
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
62
|
-
user_hash[:uid] = user_hash[:user_info]['id']
|
|
63
|
-
user_hash
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def has_callback?
|
|
67
|
-
true
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
# calculates and returns the url to which the user should be redirected,
|
|
71
|
-
# to get authenticated at the external provider's site.
|
|
72
|
-
def login_url(params,session)
|
|
73
|
-
self.authorize_url
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
# overrides oauth2#authorize_url to allow customized scope.
|
|
77
|
-
def authorize_url
|
|
78
|
-
@scope = self.access_permissions.present? ? self.access_permissions.join(",") : @scope
|
|
79
|
-
super
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# tries to login the user from access token
|
|
83
|
-
def process_callback(params,session)
|
|
84
|
-
args = {}
|
|
85
|
-
options = { :token_url => @token_url, :mode => @mode, :param_name => @param_name, :parse => @parse }
|
|
86
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
87
|
-
return self.get_access_token(args, options)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
init
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with github.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.github'.
|
|
8
|
-
# Via this new option you can configure Github specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.github.key = <key>
|
|
11
|
-
# config.github.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Github
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :github # access to github_client.
|
|
19
|
-
|
|
20
|
-
def merge_github_defaults!
|
|
21
|
-
@defaults.merge!(:@github => GithubClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_github_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module GithubClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:auth_path,
|
|
36
|
-
:token_path,
|
|
37
|
-
:site,
|
|
38
|
-
:scope,
|
|
39
|
-
:user_info_path,
|
|
40
|
-
:user_info_mapping,
|
|
41
|
-
:state
|
|
42
|
-
attr_reader :access_token
|
|
43
|
-
|
|
44
|
-
include Protocols::Oauth2
|
|
45
|
-
|
|
46
|
-
def init
|
|
47
|
-
@site = "https://github.com/"
|
|
48
|
-
@user_info_path = "https://api.github.com/user"
|
|
49
|
-
@scope = nil
|
|
50
|
-
@auth_path = "/login/oauth/authorize"
|
|
51
|
-
@token_path = "/login/oauth/access_token"
|
|
52
|
-
@user_info_mapping = {}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def get_user_hash(access_token)
|
|
56
|
-
user_hash = {}
|
|
57
|
-
response = access_token.get(@user_info_path)
|
|
58
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
59
|
-
user_hash[:uid] = user_hash[:user_info]['id']
|
|
60
|
-
user_hash
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def has_callback?
|
|
64
|
-
true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# calculates and returns the url to which the user should be redirected,
|
|
68
|
-
# to get authenticated at the external provider's site.
|
|
69
|
-
def login_url(params,session)
|
|
70
|
-
self.authorize_url({:authorize_url => @auth_path})
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# tries to login the user from access token
|
|
74
|
-
def process_callback(params,session)
|
|
75
|
-
args = {}
|
|
76
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
77
|
-
options = {
|
|
78
|
-
:token_url => @token_path,
|
|
79
|
-
:token_method => :post
|
|
80
|
-
}
|
|
81
|
-
return self.get_access_token(args, options)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
init
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with google.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.google'.
|
|
8
|
-
# Via this new option you can configure Google specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.google.key = <key>
|
|
11
|
-
# config.google.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Google
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :google # access to google_client.
|
|
19
|
-
|
|
20
|
-
def merge_google_defaults!
|
|
21
|
-
@defaults.merge!(:@google => GoogleClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_google_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module GoogleClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:site,
|
|
36
|
-
:auth_url,
|
|
37
|
-
:token_path,
|
|
38
|
-
:user_info_url,
|
|
39
|
-
:scope,
|
|
40
|
-
:user_info_mapping,
|
|
41
|
-
:state
|
|
42
|
-
attr_reader :access_token
|
|
43
|
-
|
|
44
|
-
include Protocols::Oauth2
|
|
45
|
-
|
|
46
|
-
def init
|
|
47
|
-
@site = "https://accounts.google.com"
|
|
48
|
-
@auth_url = "/o/oauth2/auth"
|
|
49
|
-
@token_url = "/o/oauth2/token"
|
|
50
|
-
@user_info_url = "https://www.googleapis.com/oauth2/v1/userinfo"
|
|
51
|
-
@scope = "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
|
|
52
|
-
@user_info_mapping = {}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def get_user_hash(access_token)
|
|
56
|
-
user_hash = {}
|
|
57
|
-
response = access_token.get(@user_info_url)
|
|
58
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
59
|
-
user_hash[:uid] = user_hash[:user_info]['id']
|
|
60
|
-
user_hash
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def has_callback?
|
|
64
|
-
true
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# calculates and returns the url to which the user should be redirected,
|
|
68
|
-
# to get authenticated at the external provider's site.
|
|
69
|
-
def login_url(params,session)
|
|
70
|
-
self.authorize_url({:authorize_url => @auth_url})
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# tries to login the user from access token
|
|
74
|
-
def process_callback(params,session)
|
|
75
|
-
args = {}
|
|
76
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
77
|
-
options = {
|
|
78
|
-
:token_url => @token_url,
|
|
79
|
-
:token_method => :post
|
|
80
|
-
}
|
|
81
|
-
return self.get_access_token(args, options)
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
init
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with Linkedin.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.linkedin'.
|
|
8
|
-
# Via this new option you can configure Linkedin specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.linkedin.key = <key>
|
|
11
|
-
# config.linkedin.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Linkedin
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :linkedin
|
|
19
|
-
|
|
20
|
-
def merge_linkedin_defaults!
|
|
21
|
-
@defaults.merge!(:@linkedin => LinkedinClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_linkedin_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module LinkedinClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:site,
|
|
36
|
-
:authorize_path,
|
|
37
|
-
:request_token_path,
|
|
38
|
-
:access_token_path,
|
|
39
|
-
:user_info_path,
|
|
40
|
-
:user_info_mapping,
|
|
41
|
-
:user_info_fields,
|
|
42
|
-
:access_permissions,
|
|
43
|
-
:state
|
|
44
|
-
attr_reader :access_token
|
|
45
|
-
|
|
46
|
-
include Protocols::Oauth1
|
|
47
|
-
|
|
48
|
-
# Override included get_consumer method to provide authorize_path
|
|
49
|
-
def get_consumer
|
|
50
|
-
# Add access permissions to request token path
|
|
51
|
-
@configuration[:request_token_path] += "?scope=" + self.access_permissions.join('+') unless self.access_permissions.blank? or @configuration[:request_token_path].include? "?scope="
|
|
52
|
-
::OAuth::Consumer.new(@key, @secret, @configuration)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def init
|
|
56
|
-
@configuration = {
|
|
57
|
-
site: "https://api.linkedin.com",
|
|
58
|
-
authorize_path: '/uas/oauth/authenticate',
|
|
59
|
-
request_token_path: '/uas/oauth/requestToken',
|
|
60
|
-
access_token_path: '/uas/oauth/accessToken'
|
|
61
|
-
}
|
|
62
|
-
@user_info_path = "/v1/people/~"
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def get_user_hash(access_token)
|
|
66
|
-
user_hash = {}
|
|
67
|
-
fields = self.user_info_fields.join(',')
|
|
68
|
-
response = access_token.get("#{@user_info_path}:(#{fields})", 'x-li-format' => 'json')
|
|
69
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
70
|
-
user_hash[:uid] = user_hash[:user_info]['id'].to_s
|
|
71
|
-
user_hash
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def has_callback?
|
|
75
|
-
true
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# calculates and returns the url to which the user should be redirected,
|
|
79
|
-
# to get authenticated at the external provider's site.
|
|
80
|
-
def login_url(params,session)
|
|
81
|
-
req_token = self.get_request_token
|
|
82
|
-
session[:request_token] = req_token.token
|
|
83
|
-
session[:request_token_secret] = req_token.secret
|
|
84
|
-
self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# tries to login the user from access token
|
|
88
|
-
def process_callback(params,session)
|
|
89
|
-
args = {}
|
|
90
|
-
args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
|
|
91
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
92
|
-
return self.get_access_token(args)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
end
|
|
96
|
-
init
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with microsoft liveid
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.liveid'.
|
|
8
|
-
# Via this new option you can configure LiveId specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.liveid.key = <key>
|
|
11
|
-
# config.liveid.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Liveid
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :liveid # access to liveid_client.
|
|
19
|
-
|
|
20
|
-
def merge_liveid_defaults!
|
|
21
|
-
@defaults.merge!(:@liveid => LiveidClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_liveid_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module LiveidClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:site,
|
|
36
|
-
:auth_url,
|
|
37
|
-
:token_path,
|
|
38
|
-
:user_info_url,
|
|
39
|
-
:scope,
|
|
40
|
-
:user_info_mapping,
|
|
41
|
-
:state
|
|
42
|
-
attr_reader :access_token
|
|
43
|
-
|
|
44
|
-
include Protocols::Oauth2
|
|
45
|
-
|
|
46
|
-
def init
|
|
47
|
-
@site = "https://oauth.live.com/"
|
|
48
|
-
@auth_url = "/authorize"
|
|
49
|
-
@token_path = "/token"
|
|
50
|
-
@user_info_url = "https://apis.live.net/v5.0/me"
|
|
51
|
-
@scope = "wl.basic wl.emails wl.offline_access"
|
|
52
|
-
@user_info_mapping = {}
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def get_user_hash(access_token)
|
|
56
|
-
user_hash = {}
|
|
57
|
-
access_token.token_param = "access_token"
|
|
58
|
-
response = access_token.get(@user_info_url)
|
|
59
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
60
|
-
user_hash[:uid] = user_hash[:user_info]['id']
|
|
61
|
-
user_hash
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def has_callback?
|
|
65
|
-
true
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# calculates and returns the url to which the user should be redirected,
|
|
69
|
-
# to get authenticated at the external provider's site.
|
|
70
|
-
def login_url(params,session)
|
|
71
|
-
self.authorize_url({:authorize_url => @auth_url})
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# tries to login the user from access token
|
|
75
|
-
def process_callback(params,session)
|
|
76
|
-
args = {}
|
|
77
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
78
|
-
options = {
|
|
79
|
-
:access_token_path => @token_path,
|
|
80
|
-
:access_token_method => :post
|
|
81
|
-
}
|
|
82
|
-
return self.get_access_token(args, options)
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
init
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with Twitter.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.twitter'.
|
|
8
|
-
# Via this new option you can configure Twitter specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.twitter.key = <key>
|
|
11
|
-
# config.twitter.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Twitter
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :twitter
|
|
19
|
-
# def twitter(&blk) # allows block syntax.
|
|
20
|
-
# yield @twitter
|
|
21
|
-
# end
|
|
22
|
-
|
|
23
|
-
def merge_twitter_defaults!
|
|
24
|
-
@defaults.merge!(:@twitter => TwitterClient)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
merge_twitter_defaults!
|
|
28
|
-
update!
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
module TwitterClient
|
|
33
|
-
include Base::BaseClient
|
|
34
|
-
class << self
|
|
35
|
-
attr_accessor :key,
|
|
36
|
-
:secret,
|
|
37
|
-
:callback_url,
|
|
38
|
-
:site,
|
|
39
|
-
:user_info_path,
|
|
40
|
-
:user_info_mapping,
|
|
41
|
-
:state
|
|
42
|
-
attr_reader :access_token
|
|
43
|
-
|
|
44
|
-
include Protocols::Oauth1
|
|
45
|
-
|
|
46
|
-
# Override included get_consumer method to provide authorize_path
|
|
47
|
-
def get_consumer
|
|
48
|
-
::OAuth::Consumer.new(@key, @secret, :site => @site, :authorize_path => "/oauth/authenticate")
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def init
|
|
52
|
-
@site = "https://api.twitter.com"
|
|
53
|
-
@user_info_path = "/1.1/account/verify_credentials.json"
|
|
54
|
-
@user_info_mapping = {}
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def get_user_hash(access_token)
|
|
58
|
-
user_hash = {}
|
|
59
|
-
response = access_token.get(@user_info_path)
|
|
60
|
-
user_hash[:user_info] = JSON.parse(response.body)
|
|
61
|
-
user_hash[:uid] = user_hash[:user_info]['id'].to_s
|
|
62
|
-
user_hash
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def has_callback?
|
|
66
|
-
true
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# calculates and returns the url to which the user should be redirected,
|
|
70
|
-
# to get authenticated at the external provider's site.
|
|
71
|
-
def login_url(params, session)
|
|
72
|
-
req_token = self.get_request_token
|
|
73
|
-
session[:request_token] = req_token.token
|
|
74
|
-
session[:request_token_secret] = req_token.secret
|
|
75
|
-
self.authorize_url({:request_token => req_token.token, :request_token_secret => req_token.secret})
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# tries to login the user from access token
|
|
79
|
-
def process_callback(params, session)
|
|
80
|
-
args = {}
|
|
81
|
-
args.merge!({:oauth_verifier => params[:oauth_verifier], :request_token => session[:request_token], :request_token_secret => session[:request_token_secret]})
|
|
82
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
83
|
-
return self.get_access_token(args)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
init
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
module Sorcery
|
|
2
|
-
module Controller
|
|
3
|
-
module Submodules
|
|
4
|
-
module External
|
|
5
|
-
module Providers
|
|
6
|
-
# This module adds support for OAuth with vk.com.
|
|
7
|
-
# When included in the 'config.providers' option, it adds a new option, 'config.vk'.
|
|
8
|
-
# Via this new option you can configure Vk specific settings like your app's key and secret.
|
|
9
|
-
#
|
|
10
|
-
# config.vk.key = <key>
|
|
11
|
-
# config.vk.secret = <secret>
|
|
12
|
-
# ...
|
|
13
|
-
#
|
|
14
|
-
module Vk
|
|
15
|
-
def self.included(base)
|
|
16
|
-
base.module_eval do
|
|
17
|
-
class << self
|
|
18
|
-
attr_reader :vk # access to vk_client.
|
|
19
|
-
|
|
20
|
-
def merge_vk_defaults!
|
|
21
|
-
@defaults.merge!(:@vk => VkClient)
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
merge_vk_defaults!
|
|
25
|
-
update!
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
module VkClient
|
|
30
|
-
include Base::BaseClient
|
|
31
|
-
class << self
|
|
32
|
-
attr_accessor :key,
|
|
33
|
-
:secret,
|
|
34
|
-
:callback_url,
|
|
35
|
-
:auth_path,
|
|
36
|
-
:token_path,
|
|
37
|
-
:site,
|
|
38
|
-
:user_info_mapping,
|
|
39
|
-
:state
|
|
40
|
-
attr_reader :access_token
|
|
41
|
-
|
|
42
|
-
include Protocols::Oauth2
|
|
43
|
-
|
|
44
|
-
def init
|
|
45
|
-
@site = "https://oauth.vk.com/"
|
|
46
|
-
@user_info_url = "https://api.vk.com/method/getProfiles"
|
|
47
|
-
@auth_path = "/authorize"
|
|
48
|
-
@token_path = "/access_token"
|
|
49
|
-
@user_info_mapping = {}
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def get_user_hash(access_token)
|
|
53
|
-
user_hash = {}
|
|
54
|
-
|
|
55
|
-
params = {
|
|
56
|
-
:access_token => access_token.token,
|
|
57
|
-
:uids => access_token.params["user_id"],
|
|
58
|
-
:fields => @user_info_mapping.values.join(",")
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
response = access_token.get(@user_info_url, :params => params)
|
|
62
|
-
if user_hash[:user_info] = JSON.parse(response.body)
|
|
63
|
-
user_hash[:user_info] = user_hash[:user_info]["response"][0]
|
|
64
|
-
# add full_name - useful if you do not store it in separate fields
|
|
65
|
-
user_hash[:user_info]["full_name"] = [user_hash[:user_info]["first_name"], user_hash[:user_info]["last_name"]].join(" ")
|
|
66
|
-
user_hash[:uid] = user_hash[:user_info]["uid"]
|
|
67
|
-
end
|
|
68
|
-
user_hash
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def has_callback?
|
|
72
|
-
true
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# calculates and returns the url to which the user should be redirected,
|
|
76
|
-
# to get authenticated at the external provider's site.
|
|
77
|
-
def login_url(params,session)
|
|
78
|
-
self.authorize_url({:authorize_url => @auth_path})
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# tries to login the user from access token
|
|
82
|
-
def process_callback(params,session)
|
|
83
|
-
args = {}
|
|
84
|
-
args.merge!({:code => params[:code]}) if params[:code]
|
|
85
|
-
options = {
|
|
86
|
-
:token_url => @token_path,
|
|
87
|
-
:token_method => :post
|
|
88
|
-
}
|
|
89
|
-
return self.get_access_token(args, options)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
end
|
|
93
|
-
init
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|