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.

Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -104
  3. data/CHANGELOG.md +13 -1
  4. data/Gemfile +2 -16
  5. data/README.md +124 -272
  6. data/Rakefile +2 -2
  7. data/gemfiles/{mongoid-rails40.gemfile → active_record-rails42.gemfile} +1 -3
  8. data/lib/generators/sorcery/helpers.rb +4 -4
  9. data/lib/generators/sorcery/install_generator.rb +25 -19
  10. data/lib/generators/sorcery/templates/initializer.rb +27 -52
  11. data/lib/generators/sorcery/templates/migration/activity_logging.rb +2 -2
  12. data/lib/generators/sorcery/templates/migration/brute_force_protection.rb +1 -1
  13. data/lib/generators/sorcery/templates/migration/core.rb +3 -3
  14. data/lib/generators/sorcery/templates/migration/external.rb +2 -2
  15. data/lib/generators/sorcery/templates/migration/remember_me.rb +2 -2
  16. data/lib/generators/sorcery/templates/migration/reset_password.rb +2 -2
  17. data/lib/generators/sorcery/templates/migration/user_activation.rb +2 -2
  18. data/lib/sorcery.rb +0 -28
  19. data/lib/sorcery/adapters/active_record_adapter.rb +7 -18
  20. data/lib/sorcery/controller.rb +19 -21
  21. data/lib/sorcery/controller/config.rb +20 -18
  22. data/lib/sorcery/controller/submodules/activity_logging.rb +7 -15
  23. data/lib/sorcery/controller/submodules/brute_force_protection.rb +1 -2
  24. data/lib/sorcery/controller/submodules/external.rb +22 -14
  25. data/lib/sorcery/controller/submodules/http_basic_auth.rb +16 -19
  26. data/lib/sorcery/controller/submodules/remember_me.rb +15 -10
  27. data/lib/sorcery/controller/submodules/session_timeout.rb +7 -8
  28. data/lib/sorcery/crypto_providers/aes256.rb +15 -15
  29. data/lib/sorcery/crypto_providers/bcrypt.rb +19 -21
  30. data/lib/sorcery/crypto_providers/common.rb +1 -1
  31. data/lib/sorcery/crypto_providers/md5.rb +5 -5
  32. data/lib/sorcery/crypto_providers/sha1.rb +5 -5
  33. data/lib/sorcery/crypto_providers/sha256.rb +2 -2
  34. data/lib/sorcery/crypto_providers/sha512.rb +3 -3
  35. data/lib/sorcery/engine.rb +3 -8
  36. data/lib/sorcery/model.rb +24 -32
  37. data/lib/sorcery/model/config.rb +64 -49
  38. data/lib/sorcery/model/submodules/activity_logging.rb +31 -12
  39. data/lib/sorcery/model/submodules/brute_force_protection.rb +23 -23
  40. data/lib/sorcery/model/submodules/external.rb +3 -7
  41. data/lib/sorcery/model/submodules/remember_me.rb +19 -7
  42. data/lib/sorcery/model/submodules/reset_password.rb +32 -36
  43. data/lib/sorcery/model/submodules/user_activation.rb +38 -50
  44. data/lib/sorcery/model/temporary_token.rb +2 -2
  45. data/lib/sorcery/protocols/oauth.rb +3 -9
  46. data/lib/sorcery/protocols/oauth2.rb +0 -2
  47. data/lib/sorcery/providers/base.rb +4 -4
  48. data/lib/sorcery/providers/facebook.rb +5 -8
  49. data/lib/sorcery/providers/github.rb +5 -7
  50. data/lib/sorcery/providers/google.rb +3 -5
  51. data/lib/sorcery/providers/heroku.rb +6 -8
  52. data/lib/sorcery/providers/jira.rb +12 -17
  53. data/lib/sorcery/providers/linkedin.rb +6 -8
  54. data/lib/sorcery/providers/liveid.rb +4 -7
  55. data/lib/sorcery/providers/paypal.rb +60 -0
  56. data/lib/sorcery/providers/salesforce.rb +3 -5
  57. data/lib/sorcery/providers/slack.rb +45 -0
  58. data/lib/sorcery/providers/twitter.rb +4 -6
  59. data/lib/sorcery/providers/vk.rb +3 -5
  60. data/lib/sorcery/providers/wechat.rb +79 -0
  61. data/lib/sorcery/providers/xing.rb +7 -10
  62. data/lib/sorcery/test_helpers/internal.rb +10 -10
  63. data/lib/sorcery/test_helpers/internal/rails.rb +16 -8
  64. data/lib/sorcery/test_helpers/rails/controller.rb +1 -1
  65. data/lib/sorcery/test_helpers/rails/integration.rb +5 -6
  66. data/lib/sorcery/version.rb +1 -1
  67. data/sorcery.gemspec +25 -27
  68. data/spec/active_record/user_activation_spec.rb +2 -3
  69. data/spec/active_record/user_activity_logging_spec.rb +2 -4
  70. data/spec/active_record/user_brute_force_protection_spec.rb +3 -4
  71. data/spec/active_record/user_oauth_spec.rb +3 -4
  72. data/spec/active_record/user_remember_me_spec.rb +3 -4
  73. data/spec/active_record/user_reset_password_spec.rb +2 -3
  74. data/spec/active_record/user_spec.rb +7 -7
  75. data/spec/controllers/controller_activity_logging_spec.rb +13 -24
  76. data/spec/controllers/controller_brute_force_protection_spec.rb +6 -8
  77. data/spec/controllers/controller_http_basic_auth_spec.rb +19 -20
  78. data/spec/controllers/controller_oauth2_spec.rb +125 -100
  79. data/spec/controllers/controller_oauth_spec.rb +86 -66
  80. data/spec/controllers/controller_remember_me_spec.rb +35 -30
  81. data/spec/controllers/controller_session_timeout_spec.rb +14 -15
  82. data/spec/controllers/controller_spec.rb +77 -111
  83. data/spec/orm/active_record.rb +1 -1
  84. data/spec/rails_app/app/active_record/authentication.rb +1 -1
  85. data/spec/rails_app/app/active_record/user.rb +2 -2
  86. data/spec/rails_app/app/controllers/sorcery_controller.rb +89 -24
  87. data/spec/rails_app/app/mailers/sorcery_mailer.rb +16 -17
  88. data/spec/rails_app/config.ru +1 -1
  89. data/spec/rails_app/config/application.rb +7 -7
  90. data/spec/rails_app/config/boot.rb +1 -1
  91. data/spec/rails_app/config/environments/test.rb +1 -1
  92. data/spec/rails_app/config/initializers/compatible_legacy_migration.rb +11 -0
  93. data/spec/rails_app/config/initializers/session_store.rb +3 -3
  94. data/spec/rails_app/config/routes.rb +11 -1
  95. data/spec/rails_app/db/migrate/activation/20101224223622_add_activation_to_users.rb +4 -4
  96. data/spec/rails_app/db/migrate/activity_logging/20101224223624_add_activity_logging_to_users.rb +8 -8
  97. data/spec/rails_app/db/migrate/brute_force_protection/20101224223626_add_brute_force_protection_to_users.rb +5 -5
  98. data/spec/rails_app/db/migrate/core/20101224223620_create_users.rb +5 -5
  99. data/spec/rails_app/db/migrate/external/20101224223628_create_authentications_and_user_providers.rb +3 -3
  100. data/spec/rails_app/db/migrate/remember_me/20101224223623_add_remember_me_token_to_users.rb +6 -6
  101. data/spec/rails_app/db/migrate/reset_password/20101224223622_add_reset_password_to_users.rb +5 -5
  102. data/spec/shared_examples/user_activation_shared_examples.rb +99 -58
  103. data/spec/shared_examples/user_activity_logging_shared_examples.rb +47 -41
  104. data/spec/shared_examples/user_brute_force_protection_shared_examples.rb +19 -24
  105. data/spec/shared_examples/user_oauth_shared_examples.rb +7 -10
  106. data/spec/shared_examples/user_remember_me_shared_examples.rb +90 -21
  107. data/spec/shared_examples/user_reset_password_shared_examples.rb +52 -54
  108. data/spec/shared_examples/user_shared_examples.rb +215 -118
  109. data/spec/sorcery_crypto_providers_spec.rb +63 -76
  110. data/spec/spec_helper.rb +17 -13
  111. metadata +28 -83
  112. data/gemfiles/mongo_mapper-rails40.gemfile +0 -9
  113. data/gemfiles/mongo_mapper-rails41.gemfile +0 -9
  114. data/gemfiles/mongoid-rails41.gemfile +0 -9
  115. data/gemfiles/mongoid3-rails32.gemfile +0 -9
  116. data/lib/sorcery/adapters/data_mapper_adapter.rb +0 -176
  117. data/lib/sorcery/adapters/mongo_mapper_adapter.rb +0 -110
  118. data/lib/sorcery/adapters/mongoid_adapter.rb +0 -97
  119. data/lib/sorcery/railties/tasks.rake +0 -6
  120. data/spec/data_mapper/user_activation_spec.rb +0 -10
  121. data/spec/data_mapper/user_activity_logging_spec.rb +0 -14
  122. data/spec/data_mapper/user_brute_force_protection_spec.rb +0 -9
  123. data/spec/data_mapper/user_oauth_spec.rb +0 -9
  124. data/spec/data_mapper/user_remember_me_spec.rb +0 -8
  125. data/spec/data_mapper/user_reset_password_spec.rb +0 -8
  126. data/spec/data_mapper/user_spec.rb +0 -27
  127. data/spec/mongo_mapper/user_activation_spec.rb +0 -9
  128. data/spec/mongo_mapper/user_activity_logging_spec.rb +0 -8
  129. data/spec/mongo_mapper/user_brute_force_protection_spec.rb +0 -8
  130. data/spec/mongo_mapper/user_oauth_spec.rb +0 -8
  131. data/spec/mongo_mapper/user_remember_me_spec.rb +0 -8
  132. data/spec/mongo_mapper/user_reset_password_spec.rb +0 -8
  133. data/spec/mongo_mapper/user_spec.rb +0 -37
  134. data/spec/mongoid/user_activation_spec.rb +0 -9
  135. data/spec/mongoid/user_activity_logging_spec.rb +0 -8
  136. data/spec/mongoid/user_brute_force_protection_spec.rb +0 -8
  137. data/spec/mongoid/user_oauth_spec.rb +0 -8
  138. data/spec/mongoid/user_remember_me_spec.rb +0 -8
  139. data/spec/mongoid/user_reset_password_spec.rb +0 -8
  140. data/spec/mongoid/user_spec.rb +0 -51
  141. data/spec/orm/data_mapper.rb +0 -48
  142. data/spec/orm/mongo_mapper.rb +0 -10
  143. data/spec/orm/mongoid.rb +0 -22
  144. data/spec/rails_app/app/data_mapper/authentication.rb +0 -8
  145. data/spec/rails_app/app/data_mapper/user.rb +0 -7
  146. data/spec/rails_app/app/mongo_mapper/authentication.rb +0 -6
  147. data/spec/rails_app/app/mongo_mapper/user.rb +0 -7
  148. data/spec/rails_app/app/mongoid/authentication.rb +0 -7
  149. 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
- attr_accessor :activation_state_attribute_name, # the attribute name to hold activation state
12
- # (active/pending).
13
-
14
- :activation_token_attribute_name, # the attribute name to hold activation code
15
- # (sent by email).
16
-
17
- :activation_token_expires_at_attribute_name, # the attribute name to hold activation code
18
- # expiration date.
19
-
20
- :activation_token_expiration_period, # how many seconds before the activation code
21
- # expires. nil for never expires.
22
-
23
- :user_activation_mailer, # your mailer class. Required when
24
- # activation_mailer_disabled == false.
25
-
26
- :activation_mailer_disabled, # when true sorcery will not automatically
27
- # email activation details and allow you to
28
- # manually handle how and when email is sent
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, :if => Proc.new { |user| user.send(sorcery_config.password_attribute_name).present? }
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!, :if => :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
- msg = "To use user_activation submodule, you must define a mailer (config.user_activation_mailer = YourMailerClass)."
85
- raise ArgumentError, msg if @sorcery_config.user_activation_mailer == nil and @sorcery_config.activation_mailer_disabled == false
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
- self.class_eval do
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
- self.send(:"#{config.activation_token_attribute_name}=", generated_activation_token)
102
- self.send(:"#{config.activation_state_attribute_name}=", "pending")
103
- self.send(:"#{config.activation_token_expires_at_attribute_name}=", Time.now.in_time_zone + config.activation_token_expiration_period) if config.activation_token_expiration_period
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
- self.send(:"#{config.activation_token_attribute_name}=", nil)
110
- self.send(:"#{config.activation_state_attribute_name}=", "active")
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(:validate => false, :raise_on_failure => true)
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
- sorcery_config.activation_mailer_disabled == true)
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
- sorcery_config.activation_mailer_disabled == true)
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 ? self.send(config.activation_state_attribute_name) == "active" : true
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.base64(15).tr('+/=lIO0', 'pqrsxyz')
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
@@ -3,7 +3,6 @@ require 'oauth2'
3
3
  module Sorcery
4
4
  module Protocols
5
5
  module Oauth2
6
-
7
6
  def oauth_version
8
7
  '2.0'
9
8
  end
@@ -41,7 +40,6 @@ module Sorcery
41
40
  defaults.merge!(options)
42
41
  )
43
42
  end
44
-
45
43
  end
46
44
  end
47
45
  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?; true; end
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(params, session)
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::join(@site, api_version.to_s),
54
- authorize_url: File::join(@auth_site, api_version.to_s, auth_path),
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, session)
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
- param_name: param_name, parse: parse)
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(params, session)
39
- authorize_url({ authorize_url: auth_path })
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, session)
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 + "/emails")
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(params, session)
37
- authorize_url({ authorize_url: auth_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, session)
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(params, session)
44
- authorize_url({ authorize_url: auth_path })
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, session)
49
- raise "Invalid state. Potential Cross Site Forgery" if params[:state] != state
50
- args = { }.tap do |a|
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
- authorize_path: '/authorize',
20
- request_token_path: '/request-token',
21
- access_token_path: '/access-token'
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
- site: site,
31
- signature_method: signature_method,
32
- consumer_key: key,
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(params, session)
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.merge!({ code: params[:code] }) if params[:code]
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