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
@@ -8,33 +8,24 @@ module Sorcery
|
|
8
8
|
module UserActivation
|
9
9
|
def self.included(base)
|
10
10
|
base.sorcery_config.class_eval do
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
:activation_needed_email_method_name, # activation needed email method on your
|
31
|
-
# mailer class.
|
32
|
-
|
33
|
-
:activation_success_email_method_name, # activation success email method on your
|
34
|
-
# mailer class.
|
35
|
-
|
36
|
-
:prevent_non_active_users_to_login # do you want to prevent or allow users that
|
37
|
-
# did not activate by email to login?
|
11
|
+
# The attribute name to hold activation state (active/pending).
|
12
|
+
attr_accessor :activation_state_attribute_name
|
13
|
+
# The attribute name to hold activation code (sent by email).
|
14
|
+
attr_accessor :activation_token_attribute_name
|
15
|
+
# The attribute name to hold activation code expiration date.
|
16
|
+
attr_accessor :activation_token_expires_at_attribute_name
|
17
|
+
# How many seconds before the activation code expires. nil for never expires.
|
18
|
+
attr_accessor :activation_token_expiration_period
|
19
|
+
# Your mailer class. Required when activation_mailer_disabled == false.
|
20
|
+
attr_accessor :user_activation_mailer
|
21
|
+
# When true sorcery will not automatically email activation details and allow you to manually handle how and when email is sent
|
22
|
+
attr_accessor :activation_mailer_disabled
|
23
|
+
# Activation needed email method on your mailer class.
|
24
|
+
attr_accessor :activation_needed_email_method_name
|
25
|
+
# Activation success email method on your mailer class.
|
26
|
+
attr_accessor :activation_success_email_method_name
|
27
|
+
# Do you want to prevent or allow users that did not activate by email to login?
|
28
|
+
attr_accessor :prevent_non_active_users_to_login
|
38
29
|
end
|
39
30
|
|
40
31
|
base.sorcery_config.instance_eval do
|
@@ -52,9 +43,9 @@ module Sorcery
|
|
52
43
|
|
53
44
|
base.class_eval do
|
54
45
|
# don't setup activation if no password supplied - this user is created automatically
|
55
|
-
sorcery_adapter.define_callback :before, :create, :setup_activation, :
|
46
|
+
sorcery_adapter.define_callback :before, :create, :setup_activation, if: proc { |user| user.send(sorcery_config.password_attribute_name).present? }
|
56
47
|
# don't send activation needed email if no crypted password created - this user is external (OAuth etc.)
|
57
|
-
sorcery_adapter.define_callback :after, :create, :send_activation_needed_email!, :
|
48
|
+
sorcery_adapter.define_callback :after, :create, :send_activation_needed_email!, if: :send_activation_needed_email?
|
58
49
|
end
|
59
50
|
|
60
51
|
base.sorcery_config.after_config << :validate_mailer_defined
|
@@ -63,8 +54,6 @@ module Sorcery
|
|
63
54
|
|
64
55
|
base.extend(ClassMethods)
|
65
56
|
base.send(:include, InstanceMethods)
|
66
|
-
|
67
|
-
|
68
57
|
end
|
69
58
|
|
70
59
|
module ClassMethods
|
@@ -81,12 +70,12 @@ module Sorcery
|
|
81
70
|
# This submodule requires the developer to define his own mailer class to be used by it
|
82
71
|
# when activation_mailer_disabled is false
|
83
72
|
def validate_mailer_defined
|
84
|
-
|
85
|
-
raise ArgumentError,
|
73
|
+
message = 'To use user_activation submodule, you must define a mailer (config.user_activation_mailer = YourMailerClass).'
|
74
|
+
raise ArgumentError, message if @sorcery_config.user_activation_mailer.nil? && @sorcery_config.activation_mailer_disabled == false
|
86
75
|
end
|
87
76
|
|
88
77
|
def define_user_activation_fields
|
89
|
-
|
78
|
+
class_eval do
|
90
79
|
sorcery_adapter.define_field sorcery_config.activation_state_attribute_name, String
|
91
80
|
sorcery_adapter.define_field sorcery_config.activation_token_attribute_name, String
|
92
81
|
sorcery_adapter.define_field sorcery_config.activation_token_expires_at_attribute_name, Time
|
@@ -98,20 +87,22 @@ module Sorcery
|
|
98
87
|
def setup_activation
|
99
88
|
config = sorcery_config
|
100
89
|
generated_activation_token = TemporaryToken.generate_random_token
|
101
|
-
|
102
|
-
|
103
|
-
|
90
|
+
send(:"#{config.activation_token_attribute_name}=", generated_activation_token)
|
91
|
+
send(:"#{config.activation_state_attribute_name}=", 'pending')
|
92
|
+
send(:"#{config.activation_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.activation_token_expiration_period) if config.activation_token_expiration_period
|
104
93
|
end
|
105
94
|
|
106
95
|
# clears activation code, sets the user as 'active' and optionaly sends a success email.
|
107
96
|
def activate!
|
108
97
|
config = sorcery_config
|
109
|
-
|
110
|
-
|
98
|
+
send(:"#{config.activation_token_attribute_name}=", nil)
|
99
|
+
send(:"#{config.activation_state_attribute_name}=", 'active')
|
111
100
|
send_activation_success_email! if send_activation_success_email?
|
112
|
-
sorcery_adapter.save(:
|
101
|
+
sorcery_adapter.save(validate: false, raise_on_failure: true)
|
113
102
|
end
|
114
103
|
|
104
|
+
attr_accessor :skip_activation_needed_email, :skip_activation_success_email
|
105
|
+
|
115
106
|
protected
|
116
107
|
|
117
108
|
# called automatically after user initial creation.
|
@@ -124,24 +115,21 @@ module Sorcery
|
|
124
115
|
end
|
125
116
|
|
126
117
|
def send_activation_success_email?
|
127
|
-
!external? &&
|
128
|
-
!(sorcery_config.activation_success_email_method_name.nil? ||
|
129
|
-
|
130
|
-
)
|
118
|
+
!external? &&
|
119
|
+
!(sorcery_config.activation_success_email_method_name.nil? || sorcery_config.activation_mailer_disabled == true) &&
|
120
|
+
!skip_activation_success_email
|
131
121
|
end
|
132
122
|
|
133
123
|
def send_activation_needed_email?
|
134
|
-
!external? &&
|
135
|
-
!(sorcery_config.activation_needed_email_method_name.nil? ||
|
136
|
-
|
137
|
-
)
|
124
|
+
!external? &&
|
125
|
+
!(sorcery_config.activation_needed_email_method_name.nil? || sorcery_config.activation_mailer_disabled == true) &&
|
126
|
+
!skip_activation_needed_email
|
138
127
|
end
|
139
128
|
|
140
129
|
def prevent_non_active_login
|
141
130
|
config = sorcery_config
|
142
|
-
config.prevent_non_active_users_to_login ?
|
131
|
+
config.prevent_non_active_users_to_login ? send(config.activation_state_attribute_name) == 'active' : true
|
143
132
|
end
|
144
|
-
|
145
133
|
end
|
146
134
|
end
|
147
135
|
end
|
@@ -12,13 +12,13 @@ module Sorcery
|
|
12
12
|
|
13
13
|
# Random code, used for salt and temporary tokens.
|
14
14
|
def self.generate_random_token
|
15
|
-
SecureRandom.
|
15
|
+
SecureRandom.urlsafe_base64(15).tr('lIO0', 'sxyz')
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
19
19
|
def load_from_token(token, token_attr_name, token_expiration_date_attr)
|
20
20
|
return nil if token.blank?
|
21
|
-
user = sorcery_adapter.find_by_token(token_attr_name,token)
|
21
|
+
user = sorcery_adapter.find_by_token(token_attr_name, token)
|
22
22
|
if !user.blank? && !user.send(token_expiration_date_attr).nil?
|
23
23
|
return Time.now.in_time_zone < user.send(token_expiration_date_attr) ? user : nil
|
24
24
|
end
|
@@ -3,12 +3,11 @@ require 'oauth'
|
|
3
3
|
module Sorcery
|
4
4
|
module Protocols
|
5
5
|
module Oauth
|
6
|
-
|
7
6
|
def oauth_version
|
8
7
|
'1.0'
|
9
8
|
end
|
10
9
|
|
11
|
-
def get_request_token(token=nil,secret=nil)
|
10
|
+
def get_request_token(token = nil, secret = nil)
|
12
11
|
return ::OAuth::RequestToken.new(get_consumer, token, secret) if token && secret
|
13
12
|
get_consumer.get_request_token(oauth_callback: @callback_url)
|
14
13
|
end
|
@@ -17,18 +16,14 @@ module Sorcery
|
|
17
16
|
get_request_token(
|
18
17
|
args[:request_token],
|
19
18
|
args[:request_token_secret]
|
20
|
-
).authorize_url(
|
21
|
-
oauth_callback: @callback_url
|
22
|
-
})
|
19
|
+
).authorize_url(oauth_callback: @callback_url)
|
23
20
|
end
|
24
21
|
|
25
22
|
def get_access_token(args)
|
26
23
|
get_request_token(
|
27
24
|
args[:request_token],
|
28
25
|
args[:request_token_secret]
|
29
|
-
).get_access_token(
|
30
|
-
oauth_verifier: args[:oauth_verifier]
|
31
|
-
})
|
26
|
+
).get_access_token(oauth_verifier: args[:oauth_verifier])
|
32
27
|
end
|
33
28
|
|
34
29
|
protected
|
@@ -36,7 +31,6 @@ module Sorcery
|
|
36
31
|
def get_consumer
|
37
32
|
::OAuth::Consumer.new(@key, @secret, site: @site)
|
38
33
|
end
|
39
|
-
|
40
34
|
end
|
41
35
|
end
|
42
36
|
end
|
@@ -1,19 +1,20 @@
|
|
1
1
|
module Sorcery
|
2
2
|
module Providers
|
3
3
|
class Base
|
4
|
-
|
5
4
|
attr_reader :access_token
|
6
5
|
|
7
6
|
attr_accessor :callback_url, :key, :original_callback_url, :secret,
|
8
7
|
:site, :state, :user_info_mapping
|
9
8
|
|
10
|
-
def has_callback
|
9
|
+
def has_callback?
|
10
|
+
true
|
11
|
+
end
|
11
12
|
|
12
13
|
def initialize
|
13
14
|
@user_info_mapping = {}
|
14
15
|
end
|
15
16
|
|
16
|
-
def auth_hash(access_token, hash={})
|
17
|
+
def auth_hash(access_token, hash = {})
|
17
18
|
return hash if access_token.nil?
|
18
19
|
|
19
20
|
token_hash = hash.dup
|
@@ -32,7 +33,6 @@ module Sorcery
|
|
32
33
|
def self.descendants
|
33
34
|
ObjectSpace.each_object(Class).select { |klass| klass < self }
|
34
35
|
end
|
35
|
-
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Facebook < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_reader :mode, :param_name, :parse
|
@@ -40,18 +39,17 @@ module Sorcery
|
|
40
39
|
|
41
40
|
# calculates and returns the url to which the user should be redirected,
|
42
41
|
# to get authenticated at the external provider's site.
|
43
|
-
def login_url(
|
42
|
+
def login_url(_params, _session)
|
44
43
|
authorize_url
|
45
44
|
end
|
46
45
|
|
47
46
|
# overrides oauth2#authorize_url to allow customized scope.
|
48
47
|
def authorize_url
|
49
|
-
|
50
48
|
# Fix: replace default oauth2 options, specially to prevent the Faraday gem which
|
51
49
|
# concatenates with "/", removing the Facebook api version
|
52
50
|
options = {
|
53
|
-
site: File
|
54
|
-
authorize_url: File
|
51
|
+
site: File.join(@site, api_version.to_s),
|
52
|
+
authorize_url: File.join(@auth_site, api_version.to_s, auth_path),
|
55
53
|
token_url: token_url
|
56
54
|
}
|
57
55
|
|
@@ -60,15 +58,14 @@ module Sorcery
|
|
60
58
|
end
|
61
59
|
|
62
60
|
# tries to login the user from access token
|
63
|
-
def process_callback(params,
|
61
|
+
def process_callback(params, _session)
|
64
62
|
args = {}.tap do |a|
|
65
63
|
a[:code] = params[:code] if params[:code]
|
66
64
|
end
|
67
65
|
|
68
66
|
get_access_token(args, token_url: token_url, mode: mode,
|
69
|
-
|
67
|
+
param_name: param_name, parse: parse)
|
70
68
|
end
|
71
|
-
|
72
69
|
end
|
73
70
|
end
|
74
71
|
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Github < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_accessor :auth_path, :scope, :token_url, :user_info_path
|
@@ -35,12 +34,12 @@ 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
|
-
authorize_url(
|
37
|
+
def login_url(_params, _session)
|
38
|
+
authorize_url(authorize_url: auth_path)
|
40
39
|
end
|
41
40
|
|
42
41
|
# tries to login the user from access token
|
43
|
-
def process_callback(params,
|
42
|
+
def process_callback(params, _session)
|
44
43
|
args = {}.tap do |a|
|
45
44
|
a[:code] = params[:code] if params[:code]
|
46
45
|
end
|
@@ -49,12 +48,11 @@ module Sorcery
|
|
49
48
|
end
|
50
49
|
|
51
50
|
def primary_email(access_token)
|
52
|
-
response = access_token.get(user_info_path +
|
51
|
+
response = access_token.get(user_info_path + '/emails')
|
53
52
|
emails = JSON.parse(response.body)
|
54
|
-
primary = emails.find{|i| i['primary'] }
|
53
|
+
primary = emails.find { |i| i['primary'] }
|
55
54
|
primary && primary['email'] || emails.first && emails.first['email']
|
56
55
|
end
|
57
|
-
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
@@ -7,7 +7,6 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Google < Base
|
10
|
-
|
11
10
|
include Protocols::Oauth2
|
12
11
|
|
13
12
|
attr_accessor :auth_url, :scope, :token_url, :user_info_url
|
@@ -33,19 +32,18 @@ module Sorcery
|
|
33
32
|
|
34
33
|
# calculates and returns the url to which the user should be redirected,
|
35
34
|
# to get authenticated at the external provider's site.
|
36
|
-
def login_url(
|
37
|
-
authorize_url(
|
35
|
+
def login_url(_params, _session)
|
36
|
+
authorize_url(authorize_url: auth_url)
|
38
37
|
end
|
39
38
|
|
40
39
|
# tries to login the user from access token
|
41
|
-
def process_callback(params,
|
40
|
+
def process_callback(params, _session)
|
42
41
|
args = {}.tap do |a|
|
43
42
|
a[:code] = params[:code] if params[:code]
|
44
43
|
end
|
45
44
|
|
46
45
|
get_access_token(args, token_url: token_url, token_method: :post)
|
47
46
|
end
|
48
|
-
|
49
47
|
end
|
50
48
|
end
|
51
49
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module Sorcery
|
2
2
|
module Providers
|
3
|
-
|
4
3
|
# This class adds support for OAuth with heroku.com.
|
5
4
|
|
6
5
|
# config.heroku.key = <key>
|
@@ -13,7 +12,6 @@ module Sorcery
|
|
13
12
|
# The full path must be set for OAuth Callback URL when configuring the API Client Information on Heroku.
|
14
13
|
|
15
14
|
class Heroku < Base
|
16
|
-
|
17
15
|
include Protocols::Oauth2
|
18
16
|
|
19
17
|
attr_accessor :auth_path, :scope, :token_url, :user_info_path
|
@@ -40,18 +38,18 @@ module Sorcery
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
43
|
-
def login_url(
|
44
|
-
authorize_url(
|
41
|
+
def login_url(_params, _session)
|
42
|
+
authorize_url(authorize_url: auth_path)
|
45
43
|
end
|
46
44
|
|
47
45
|
# tries to login the user from access token
|
48
|
-
def process_callback(params,
|
49
|
-
raise
|
50
|
-
args = {
|
46
|
+
def process_callback(params, _session)
|
47
|
+
raise 'Invalid state. Potential Cross Site Forgery' if params[:state] != state
|
48
|
+
args = {}.tap do |a|
|
51
49
|
a[:code] = params[:code] if params[:code]
|
52
50
|
end
|
53
51
|
get_access_token(args, token_url: token_url, token_method: :post)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
end
|
57
|
-
end
|
55
|
+
end
|
@@ -7,31 +7,27 @@ module Sorcery
|
|
7
7
|
# ...
|
8
8
|
#
|
9
9
|
class Jira < 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, :site, :signature_method, :private_key_file, :callback_url
|
15
14
|
|
16
|
-
|
17
15
|
def initialize
|
18
16
|
@configuration = {
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
authorize_path: '/authorize',
|
18
|
+
request_token_path: '/request-token',
|
19
|
+
access_token_path: '/access-token'
|
22
20
|
}
|
23
21
|
@user_info_path = '/users/me'
|
24
22
|
end
|
25
23
|
|
26
24
|
# Override included get_consumer method to provide authorize_path
|
27
|
-
#read extra configurations
|
25
|
+
# read extra configurations
|
28
26
|
def get_consumer
|
29
|
-
@configuration = @configuration.merge(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
private_key_file: private_key_file
|
34
|
-
})
|
27
|
+
@configuration = @configuration.merge(site: site,
|
28
|
+
signature_method: signature_method,
|
29
|
+
consumer_key: key,
|
30
|
+
private_key_file: private_key_file)
|
35
31
|
::OAuth::Consumer.new(@key, @secret, @configuration)
|
36
32
|
end
|
37
33
|
|
@@ -46,13 +42,13 @@ module Sorcery
|
|
46
42
|
|
47
43
|
# calculates and returns the url to which the user should be redirected,
|
48
44
|
# to get authenticated at the external provider's site.
|
49
|
-
def login_url(
|
45
|
+
def login_url(_params, session)
|
50
46
|
req_token = get_request_token
|
51
47
|
session[:request_token] = req_token.token
|
52
48
|
session[:request_token_secret] = req_token.secret
|
53
49
|
|
54
|
-
#it was like that -> redirect_to authorize_url({ request_token: req_token.token, request_token_secret: req_token.secret })
|
55
|
-
#for some reason Jira does not need these parameters
|
50
|
+
# it was like that -> redirect_to authorize_url({ request_token: req_token.token, request_token_secret: req_token.secret })
|
51
|
+
# for some reason Jira does not need these parameters
|
56
52
|
|
57
53
|
get_request_token(
|
58
54
|
session[:request_token],
|
@@ -68,10 +64,9 @@ module Sorcery
|
|
68
64
|
request_token_secret: session[:request_token_secret]
|
69
65
|
}
|
70
66
|
|
71
|
-
args
|
67
|
+
args[:code] = params[:code] if params[:code]
|
72
68
|
get_access_token(args)
|
73
69
|
end
|
74
|
-
|
75
70
|
end
|
76
71
|
end
|
77
72
|
end
|