sorcery 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sorcery might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.travis.yml +29 -104
- data/CHANGELOG.md +13 -1
- data/Gemfile +2 -16
- data/README.md +124 -272
- data/Rakefile +2 -2
- data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
- data/lib/generators/sorcery/helpers.rb +4 -4
- data/lib/generators/sorcery/install_generator.rb +25 -19
- data/lib/generators/sorcery/templates/initializer.rb +27 -52
- data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
- data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
- data/lib/generators/sorcery/templates/migration/core.rb +3 -3
- data/lib/generators/sorcery/templates/migration/external.rb +2 -2
- data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
- data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
- data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
- data/lib/sorcery.rb +0 -28
- data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
- data/lib/sorcery/controller.rb +19 -21
- data/lib/sorcery/controller/config.rb +20 -18
- data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
- data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
- data/lib/sorcery/controller/submodules/external.rb +22 -14
- data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
- data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
- data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
- data/lib/sorcery/crypto_providers/aes256.rb +15 -15
- data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
- data/lib/sorcery/crypto_providers/common.rb +1 -1
- data/lib/sorcery/crypto_providers/md5.rb +5 -5
- data/lib/sorcery/crypto_providers/sha1.rb +5 -5
- data/lib/sorcery/crypto_providers/sha256.rb +2 -2
- data/lib/sorcery/crypto_providers/sha512.rb +3 -3
- data/lib/sorcery/engine.rb +3 -8
- data/lib/sorcery/model.rb +24 -32
- data/lib/sorcery/model/config.rb +64 -49
- data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
- data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
- data/lib/sorcery/model/submodules/external.rb +3 -7
- data/lib/sorcery/model/submodules/remember_me.rb +19 -7
- data/lib/sorcery/model/submodules/reset_password.rb +32 -36
- data/lib/sorcery/model/submodules/user_activation.rb +38 -50
- data/lib/sorcery/model/temporary_token.rb +2 -2
- data/lib/sorcery/protocols/oauth.rb +3 -9
- data/lib/sorcery/protocols/oauth2.rb +0 -2
- data/lib/sorcery/providers/base.rb +4 -4
- data/lib/sorcery/providers/facebook.rb +5 -8
- data/lib/sorcery/providers/github.rb +5 -7
- data/lib/sorcery/providers/google.rb +3 -5
- data/lib/sorcery/providers/heroku.rb +6 -8
- data/lib/sorcery/providers/jira.rb +12 -17
- data/lib/sorcery/providers/linkedin.rb +6 -8
- data/lib/sorcery/providers/liveid.rb +4 -7
- data/lib/sorcery/providers/paypal.rb +60 -0
- data/lib/sorcery/providers/salesforce.rb +3 -5
- data/lib/sorcery/providers/slack.rb +45 -0
- data/lib/sorcery/providers/twitter.rb +4 -6
- data/lib/sorcery/providers/vk.rb +3 -5
- data/lib/sorcery/providers/wechat.rb +79 -0
- data/lib/sorcery/providers/xing.rb +7 -10
- data/lib/sorcery/test_helpers/internal.rb +10 -10
- data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
- data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
- data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
- data/lib/sorcery/version.rb +1 -1
- data/sorcery.gemspec +25 -27
- data/spec/active_record/user_activation_spec.rb +2 -3
- data/spec/active_record/user_activity_logging_spec.rb +2 -4
- data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
- data/spec/active_record/user_oauth_spec.rb +3 -4
- data/spec/active_record/user_remember_me_spec.rb +3 -4
- data/spec/active_record/user_reset_password_spec.rb +2 -3
- data/spec/active_record/user_spec.rb +7 -7
- data/spec/controllers/controller_activity_logging_spec.rb +13 -24
- data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
- data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
- data/spec/controllers/controller_oauth2_spec.rb +125 -100
- data/spec/controllers/controller_oauth_spec.rb +86 -66
- data/spec/controllers/controller_remember_me_spec.rb +35 -30
- data/spec/controllers/controller_session_timeout_spec.rb +14 -15
- data/spec/controllers/controller_spec.rb +77 -111
- data/spec/orm/active_record.rb +1 -1
- data/spec/rails_app/app/active_record/authentication.rb +1 -1
- data/spec/rails_app/app/active_record/user.rb +2 -2
- data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
- data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
- data/spec/rails_app/config.ru +1 -1
- data/spec/rails_app/config/application.rb +7 -7
- data/spec/rails_app/config/boot.rb +1 -1
- data/spec/rails_app/config/environments/test.rb +1 -1
- data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
- data/spec/rails_app/config/initializers/session_store.rb +3 -3
- data/spec/rails_app/config/routes.rb +11 -1
- data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
- data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
- data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
- data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
- data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
- data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
- data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
- data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
- data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
- data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
- data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
- data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
- data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
- data/spec/shared_examples/user_shared_examples.rb +215 -118
- data/spec/sorcery_crypto_providers_spec.rb +63 -76
- data/spec/spec_helper.rb +17 -13
- metadata +28 -83
- data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
- data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
- data/gemfiles/mongoid-rails41.gemfile +0 -9
- data/gemfiles/mongoid3-rails32.gemfile +0 -9
- data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
- data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
- data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
- data/lib/sorcery/railties/tasks.rake +0 -6
- data/spec/data_mapper/user_activation_spec.rb +0 -10
- data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
- data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
- data/spec/data_mapper/user_oauth_spec.rb +0 -9
- data/spec/data_mapper/user_remember_me_spec.rb +0 -8
- data/spec/data_mapper/user_reset_password_spec.rb +0 -8
- data/spec/data_mapper/user_spec.rb +0 -27
- data/spec/mongo_mapper/user_activation_spec.rb +0 -9
- data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
- data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
- data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
- data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
- data/spec/mongo_mapper/user_spec.rb +0 -37
- data/spec/mongoid/user_activation_spec.rb +0 -9
- data/spec/mongoid/user_activity_logging_spec.rb +0 -8
- data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
- data/spec/mongoid/user_oauth_spec.rb +0 -8
- data/spec/mongoid/user_remember_me_spec.rb +0 -8
- data/spec/mongoid/user_reset_password_spec.rb +0 -8
- data/spec/mongoid/user_spec.rb +0 -51
- data/spec/orm/data_mapper.rb +0 -48
- data/spec/orm/mongo_mapper.rb +0 -10
- data/spec/orm/mongoid.rb +0 -22
- data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
- data/spec/rails_app/app/data_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
- data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
- data/spec/rails_app/app/mongoid/authentication.rb +0 -7
- data/spec/rails_app/app/mongoid/user.rb +0 -7
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Linkedin < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth
|
12
11
|
|
13
12
|
attr_accessor :authorize_path, :access_permissions, :access_token_path,
|
@@ -26,13 +25,13 @@ module Sorcery
|
|
26
25
|
# Override included get_consumer method to provide authorize_path
|
27
26
|
def get_consumer
|
28
27
|
# Add access permissions to request token path
|
29
|
-
@configuration[:request_token_path] += '?scope=' + access_permissions.join('+') unless access_permissions.blank?
|
28
|
+
@configuration[:request_token_path] += '?scope=' + access_permissions.join('+') unless access_permissions.blank? || @configuration[:request_token_path].include?('?scope=')
|
30
29
|
::OAuth::Consumer.new(@key, @secret, @configuration)
|
31
30
|
end
|
32
31
|
|
33
32
|
def get_user_hash(access_token)
|
34
|
-
fields =
|
35
|
-
response = access_token.get("#{@user_info_path}:(
|
33
|
+
fields = user_info_fields.join(',')
|
34
|
+
response = access_token.get("#{@user_info_path}:(id,#{fields})", 'x-li-format' => 'json')
|
36
35
|
|
37
36
|
auth_hash(access_token).tap do |h|
|
38
37
|
h[:user_info] = JSON.parse(response.body)
|
@@ -42,11 +41,11 @@ module Sorcery
|
|
42
41
|
|
43
42
|
# calculates and returns the url to which the user should be redirected,
|
44
43
|
# to get authenticated at the external provider's site.
|
45
|
-
def login_url(
|
44
|
+
def login_url(_params, session)
|
46
45
|
req_token = get_request_token
|
47
46
|
session[:request_token] = req_token.token
|
48
47
|
session[:request_token_secret] = req_token.secret
|
49
|
-
authorize_url(
|
48
|
+
authorize_url(request_token: req_token.token, request_token_secret: req_token.secret)
|
50
49
|
end
|
51
50
|
|
52
51
|
# tries to login the user from access token
|
@@ -57,10 +56,9 @@ module Sorcery
|
|
57
56
|
request_token_secret: session[:request_token_secret]
|
58
57
|
}
|
59
58
|
|
60
|
-
args
|
59
|
+
args[:code] = params[:code] if params[:code]
|
61
60
|
get_access_token(args)
|
62
61
|
end
|
63
|
-
|
64
62
|
end
|
65
63
|
end
|
66
64
|
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Liveid < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_accessor :auth_url, :token_path, :user_info_url, :scope
|
@@ -34,20 +33,18 @@ module Sorcery
|
|
34
33
|
|
35
34
|
# calculates and returns the url to which the user should be redirected,
|
36
35
|
# to get authenticated at the external provider's site.
|
37
|
-
def login_url(
|
38
|
-
|
36
|
+
def login_url(_params, _session)
|
37
|
+
authorize_url(authorize_url: auth_url)
|
39
38
|
end
|
40
39
|
|
41
40
|
# tries to login the user from access token
|
42
|
-
def process_callback(params,
|
41
|
+
def process_callback(params, _session)
|
43
42
|
args = {}.tap do |a|
|
44
43
|
a[:code] = params[:code] if params[:code]
|
45
44
|
end
|
46
45
|
|
47
|
-
get_access_token(args, access_token_path: token_path,
|
48
|
-
access_token_method: :post)
|
46
|
+
get_access_token(args, access_token_path: token_path, access_token_method: :post)
|
49
47
|
end
|
50
|
-
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Sorcery
|
2
|
+
module Providers
|
3
|
+
# This class adds support for OAuth with paypal.com.
|
4
|
+
#
|
5
|
+
# config.paypal.key = <key>
|
6
|
+
# config.paypal.secret = <secret>
|
7
|
+
# ...
|
8
|
+
#
|
9
|
+
class Paypal < Base
|
10
|
+
include Protocols::Oauth2
|
11
|
+
|
12
|
+
attr_accessor :auth_url, :scope, :token_url, :user_info_url
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
super
|
16
|
+
|
17
|
+
@scope = 'openid email'
|
18
|
+
@site = 'https://api.paypal.com'
|
19
|
+
@auth_url = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'
|
20
|
+
@user_info_url = 'https://api.paypal.com/v1/identity/openidconnect/userinfo?schema=openid'
|
21
|
+
@token_url = 'https://api.paypal.com/v1/identity/openidconnect/tokenservice'
|
22
|
+
@state = SecureRandom.hex(16)
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_user_hash(access_token)
|
26
|
+
response = access_token.get(user_info_url)
|
27
|
+
body = JSON.parse(response.body)
|
28
|
+
auth_hash(access_token).tap do |h|
|
29
|
+
h[:user_info] = body
|
30
|
+
h[:uid] = body['user_id']
|
31
|
+
h[:email] = body['email']
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_access_token(args, options = {})
|
36
|
+
client = build_client(options)
|
37
|
+
client.auth_code.get_token(
|
38
|
+
args[:code],
|
39
|
+
{
|
40
|
+
redirect_uri: @callback_url,
|
41
|
+
parse: options.delete(:parse)
|
42
|
+
},
|
43
|
+
options
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
def login_url(_params, _session)
|
48
|
+
authorize_url(authorize_url: auth_url)
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_callback(params, _session)
|
52
|
+
args = {}.tap do |a|
|
53
|
+
a[:code] = params[:code] if params[:code]
|
54
|
+
end
|
55
|
+
|
56
|
+
get_access_token(args, token_url: token_url, token_method: :post)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Salesforce < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_accessor :auth_url, :token_url, :scope
|
@@ -32,19 +31,18 @@ module Sorcery
|
|
32
31
|
|
33
32
|
# calculates and returns the url to which the user should be redirected,
|
34
33
|
# to get authenticated at the external provider's site.
|
35
|
-
def login_url(
|
36
|
-
authorize_url(
|
34
|
+
def login_url(_params, _session)
|
35
|
+
authorize_url(authorize_url: auth_url)
|
37
36
|
end
|
38
37
|
|
39
38
|
# tries to login the user from access token
|
40
|
-
def process_callback(params,
|
39
|
+
def process_callback(params, _session)
|
41
40
|
args = {}.tap do |a|
|
42
41
|
a[:code] = params[:code] if params[:code]
|
43
42
|
end
|
44
43
|
|
45
44
|
get_access_token(args, token_url: token_url, token_method: :post)
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
47
|
end
|
50
48
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Sorcery
|
2
|
+
module Providers
|
3
|
+
# This class adds support for OAuth with slack.com.
|
4
|
+
|
5
|
+
class Slack < Base
|
6
|
+
include Protocols::Oauth2
|
7
|
+
|
8
|
+
attr_accessor :auth_path, :scope, :token_url, :user_info_path
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
|
13
|
+
@scope = 'identity.basic, identity.email'
|
14
|
+
@site = 'https://slack.com/'
|
15
|
+
@user_info_path = 'https://slack.com/api/users.identity'
|
16
|
+
@auth_path = '/oauth/authorize'
|
17
|
+
@token_url = '/api/oauth.access'
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_user_hash(access_token)
|
21
|
+
response = access_token.get(user_info_path, params: { token: access_token.token })
|
22
|
+
auth_hash(access_token).tap do |h|
|
23
|
+
h[:user_info] = JSON.parse(response.body)
|
24
|
+
h[:user_info]['email'] = h[:user_info]['user']['email']
|
25
|
+
h[:uid] = h[:user_info]['user']['id']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# calculates and returns the url to which the user should be redirected,
|
30
|
+
# to get authenticated at the external provider's site.
|
31
|
+
def login_url(_params, _session)
|
32
|
+
authorize_url(authorize_url: auth_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
# tries to login the user from access token
|
36
|
+
def process_callback(params, _session)
|
37
|
+
args = {}.tap do |a|
|
38
|
+
a[:code] = params[:code] if params[:code]
|
39
|
+
end
|
40
|
+
|
41
|
+
get_access_token(args, token_url: token_url, token_method: :post)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Twitter < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth
|
12
11
|
|
13
12
|
attr_accessor :state, :user_info_path
|
@@ -35,11 +34,11 @@ module Sorcery
|
|
35
34
|
|
36
35
|
# calculates and returns the url to which the user should be redirected,
|
37
36
|
# to get authenticated at the external provider's site.
|
38
|
-
def login_url(
|
39
|
-
req_token =
|
37
|
+
def login_url(_params, session)
|
38
|
+
req_token = get_request_token
|
40
39
|
session[:request_token] = req_token.token
|
41
40
|
session[:request_token_secret] = req_token.secret
|
42
|
-
|
41
|
+
authorize_url(request_token: req_token.token, request_token_secret: req_token.secret)
|
43
42
|
end
|
44
43
|
|
45
44
|
# tries to login the user from access token
|
@@ -50,10 +49,9 @@ module Sorcery
|
|
50
49
|
request_token_secret: session[:request_token_secret]
|
51
50
|
}
|
52
51
|
|
53
|
-
args
|
52
|
+
args[:code] = params[:code] if params[:code]
|
54
53
|
get_access_token(args)
|
55
54
|
end
|
56
|
-
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
data/lib/sorcery/providers/vk.rb
CHANGED
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Vk < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_accessor :auth_path, :token_path, :user_info_url, :scope
|
@@ -45,19 +44,18 @@ module Sorcery
|
|
45
44
|
|
46
45
|
# calculates and returns the url to which the user should be redirected,
|
47
46
|
# to get authenticated at the external provider's site.
|
48
|
-
def login_url(
|
49
|
-
|
47
|
+
def login_url(_params, _session)
|
48
|
+
authorize_url(authorize_url: auth_path)
|
50
49
|
end
|
51
50
|
|
52
51
|
# tries to login the user from access token
|
53
|
-
def process_callback(params,
|
52
|
+
def process_callback(params, _session)
|
54
53
|
args = {}.tap do |a|
|
55
54
|
a[:code] = params[:code] if params[:code]
|
56
55
|
end
|
57
56
|
|
58
57
|
get_access_token(args, token_url: token_path, token_method: :post)
|
59
58
|
end
|
60
|
-
|
61
59
|
end
|
62
60
|
end
|
63
61
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Sorcery
|
2
|
+
module Providers
|
3
|
+
# This class adds support for OAuth with open.wx.qq.com.
|
4
|
+
#
|
5
|
+
# config.wechat.key = <key>
|
6
|
+
# config.wechat.secret = <secret>
|
7
|
+
# ...
|
8
|
+
#
|
9
|
+
class Wechat < Base
|
10
|
+
include Protocols::Oauth2
|
11
|
+
|
12
|
+
attr_reader :mode, :param_name, :parse
|
13
|
+
attr_accessor :auth_url, :scope, :token_url, :user_info_path
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
super
|
17
|
+
|
18
|
+
@scope = 'snsapi_login'
|
19
|
+
@auth_url = 'https://open.weixin.qq.com/connect/qrconnect'
|
20
|
+
@user_info_path = 'https://api.weixin.qq.com/sns/userinfo'
|
21
|
+
@token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token'
|
22
|
+
@state = SecureRandom.hex(16)
|
23
|
+
@mode = :body
|
24
|
+
@parse = :json
|
25
|
+
@param_name = 'access_token'
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize_url(options = {})
|
29
|
+
oauth_params = {
|
30
|
+
appid: @key,
|
31
|
+
redirect_uri: @callback_url,
|
32
|
+
response_type: 'code',
|
33
|
+
scope: scope,
|
34
|
+
state: @state
|
35
|
+
}
|
36
|
+
"#{options[:authorize_url]}?#{oauth_params.to_query}#wechat_redirect"
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_user_hash(access_token)
|
40
|
+
response = access_token.get(user_info_path, params: {
|
41
|
+
access_token: access_token.token,
|
42
|
+
openid: access_token.params['openid'],
|
43
|
+
})
|
44
|
+
|
45
|
+
{}.tap do |h|
|
46
|
+
h[:user_info] = JSON.parse(response.body)
|
47
|
+
h[:uid] = h[:user_info]['unionid']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_access_token(args, options = {})
|
52
|
+
client = build_client(options)
|
53
|
+
client.auth_code.get_token(
|
54
|
+
args[:code],
|
55
|
+
{ appid: @key, secret: @secret, parse: parse },
|
56
|
+
options
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def login_url(_params, _session)
|
61
|
+
authorize_url authorize_url: auth_url
|
62
|
+
end
|
63
|
+
|
64
|
+
def process_callback(params, _session)
|
65
|
+
args = {}.tap do |a|
|
66
|
+
a[:code] = params[:code] if params[:code]
|
67
|
+
end
|
68
|
+
|
69
|
+
get_access_token(
|
70
|
+
args,
|
71
|
+
token_url: token_url,
|
72
|
+
mode: mode,
|
73
|
+
param_name: param_name,
|
74
|
+
)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -7,19 +7,17 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Xing < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth
|
12
11
|
|
13
12
|
attr_accessor :access_token_path, :authorize_path, :request_token_path,
|
14
13
|
:user_info_path
|
15
14
|
|
16
|
-
|
17
15
|
def initialize
|
18
16
|
@configuration = {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
site: 'https://api.xing.com/v1',
|
18
|
+
authorize_path: '/authorize',
|
19
|
+
request_token_path: '/request_token',
|
20
|
+
access_token_path: '/access_token'
|
23
21
|
}
|
24
22
|
@user_info_path = '/users/me'
|
25
23
|
end
|
@@ -40,11 +38,11 @@ module Sorcery
|
|
40
38
|
|
41
39
|
# calculates and returns the url to which the user should be redirected,
|
42
40
|
# to get authenticated at the external provider's site.
|
43
|
-
def login_url(
|
41
|
+
def login_url(_params, session)
|
44
42
|
req_token = get_request_token
|
45
43
|
session[:request_token] = req_token.token
|
46
44
|
session[:request_token_secret] = req_token.secret
|
47
|
-
authorize_url(
|
45
|
+
authorize_url(request_token: req_token.token, request_token_secret: req_token.secret)
|
48
46
|
end
|
49
47
|
|
50
48
|
# tries to login the user from access token
|
@@ -55,10 +53,9 @@ module Sorcery
|
|
55
53
|
request_token_secret: session[:request_token_secret]
|
56
54
|
}
|
57
55
|
|
58
|
-
args
|
56
|
+
args[:code] = params[:code] if params[:code]
|
59
57
|
get_access_token(args)
|
60
58
|
end
|
61
|
-
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
@@ -3,7 +3,7 @@ module Sorcery
|
|
3
3
|
# Internal TestHelpers are used to test the gem, internally, and should not be used to test apps *using* sorcery.
|
4
4
|
# This file will be included in the spec_helper file.
|
5
5
|
module Internal
|
6
|
-
def self.included(
|
6
|
+
def self.included(_base)
|
7
7
|
# reducing default cost for specs speed
|
8
8
|
CryptoProviders::BCrypt.class_eval do
|
9
9
|
class << self
|
@@ -24,31 +24,31 @@ module Sorcery
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def build_new_user(attributes_hash = nil)
|
27
|
-
user_attributes_hash = attributes_hash || {:
|
27
|
+
user_attributes_hash = attributes_hash || { username: 'gizmo', email: 'bla@bla.com', password: 'secret' }
|
28
28
|
@user = User.new(user_attributes_hash)
|
29
29
|
end
|
30
30
|
|
31
31
|
def create_new_user(attributes_hash = nil)
|
32
32
|
@user = build_new_user(attributes_hash)
|
33
|
-
@user.sorcery_adapter.save(:
|
33
|
+
@user.sorcery_adapter.save(raise_on_failure: true)
|
34
34
|
@user
|
35
35
|
end
|
36
36
|
|
37
37
|
def create_new_external_user(provider, attributes_hash = nil)
|
38
|
-
user_attributes_hash = attributes_hash || {:
|
38
|
+
user_attributes_hash = attributes_hash || { username: 'gizmo' }
|
39
39
|
@user = User.new(user_attributes_hash)
|
40
|
-
@user.sorcery_adapter.save(:
|
41
|
-
@user.authentications.create!(
|
40
|
+
@user.sorcery_adapter.save(raise_on_failure: true)
|
41
|
+
@user.authentications.create!(provider: provider, uid: 123)
|
42
42
|
@user
|
43
43
|
end
|
44
44
|
|
45
45
|
def custom_create_new_external_user(provider, authentication_class, attributes_hash = nil)
|
46
46
|
authentication_association = authentication_class.name.underscore.pluralize
|
47
47
|
|
48
|
-
user_attributes_hash = attributes_hash || {:
|
48
|
+
user_attributes_hash = attributes_hash || { username: 'gizmo' }
|
49
49
|
@user = User.new(user_attributes_hash)
|
50
|
-
@user.sorcery_adapter.save(:
|
51
|
-
@user.send(authentication_association).create!(
|
50
|
+
@user.sorcery_adapter.save(raise_on_failure: true)
|
51
|
+
@user.send(authentication_association).create!(provider: provider, uid: 123)
|
52
52
|
@user
|
53
53
|
end
|
54
54
|
|
@@ -67,7 +67,7 @@ module Sorcery
|
|
67
67
|
# reload user class between specs
|
68
68
|
# so it will be possible to test the different submodules in isolation
|
69
69
|
def reload_user_class
|
70
|
-
Object.send(:remove_const,
|
70
|
+
Object.send(:remove_const, 'User')
|
71
71
|
load 'user.rb'
|
72
72
|
if User.respond_to?(:reset_column_information)
|
73
73
|
User.reset_column_information
|