authkit 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -3
  3. data/Rakefile +3 -2
  4. data/lib/authkit/version.rb +1 -1
  5. data/lib/generators/authkit/install_generator.rb +181 -35
  6. data/lib/generators/authkit/templates/app/controllers/application_controller.rb +6 -0
  7. data/lib/generators/authkit/templates/app/controllers/auths_controller.rb +144 -0
  8. data/lib/generators/authkit/templates/app/controllers/email_confirmation_controller.rb +1 -1
  9. data/lib/generators/authkit/templates/app/controllers/password_reset_controller.rb +7 -1
  10. data/lib/generators/authkit/templates/app/controllers/sessions_controller.rb +11 -2
  11. data/lib/generators/authkit/templates/app/controllers/signup_controller.rb +4 -2
  12. data/lib/generators/authkit/templates/app/controllers/upload_controller.rb +78 -0
  13. data/lib/generators/authkit/templates/app/controllers/users_controller.rb +2 -2
  14. data/lib/generators/authkit/templates/app/forms/signup.rb +57 -7
  15. data/lib/generators/authkit/templates/app/helpers/auths_helper.rb +26 -0
  16. data/lib/generators/authkit/templates/app/helpers/upload_helper.rb +118 -0
  17. data/lib/generators/authkit/templates/app/models/auth.rb +81 -0
  18. data/lib/generators/authkit/templates/app/models/avatar.rb +45 -0
  19. data/lib/generators/authkit/templates/app/models/user.rb +53 -26
  20. data/lib/generators/authkit/templates/app/views/auths/connect.html.erb +34 -0
  21. data/lib/generators/authkit/templates/app/views/password_change/show.html.erb +9 -9
  22. data/lib/generators/authkit/templates/app/views/password_reset/show.html.erb +6 -6
  23. data/lib/generators/authkit/templates/app/views/sessions/new.html.erb +25 -7
  24. data/lib/generators/authkit/templates/app/views/signup/new.html.erb +44 -32
  25. data/lib/generators/authkit/templates/app/views/users/complete.html.erb +39 -0
  26. data/lib/generators/authkit/templates/app/views/users/edit.html.erb +31 -31
  27. data/lib/generators/authkit/templates/app/workers/avatar_import_worker.rb +12 -0
  28. data/lib/generators/authkit/templates/config/initializers/filter_parameter_logging.rb +2 -2
  29. data/lib/generators/authkit/templates/config/initializers/omniauth.rb +59 -0
  30. data/lib/generators/authkit/templates/config/initializers/paperclip.rb +68 -0
  31. data/lib/generators/authkit/templates/db/migrate/add_authkit_fields_to_users.rb +8 -6
  32. data/lib/generators/authkit/templates/db/migrate/create_auths.rb +24 -0
  33. data/lib/generators/authkit/templates/db/migrate/create_avatars.rb +27 -0
  34. data/lib/generators/authkit/templates/lib/full_name_splitter.rb +111 -0
  35. data/lib/generators/authkit/templates/lib/username_format_validator.rb +11 -0
  36. data/lib/generators/authkit/templates/spec/controllers/application_controller_spec.rb +31 -38
  37. data/lib/generators/authkit/templates/spec/controllers/auths_controller_spec.rb +72 -0
  38. data/lib/generators/authkit/templates/spec/controllers/email_confirmation_controller_spec.rb +25 -27
  39. data/lib/generators/authkit/templates/spec/controllers/password_change_controller_spec.rb +30 -30
  40. data/lib/generators/authkit/templates/spec/controllers/password_reset_controller_spec.rb +20 -20
  41. data/lib/generators/authkit/templates/spec/controllers/sessions_controller_spec.rb +33 -33
  42. data/lib/generators/authkit/templates/spec/controllers/signup_controller_spec.rb +19 -19
  43. data/lib/generators/authkit/templates/spec/controllers/users_controller_spec.rb +21 -21
  44. data/lib/generators/authkit/templates/spec/factories/user.rb +3 -3
  45. data/lib/generators/authkit/templates/spec/forms/signup_spec.rb +32 -31
  46. data/lib/generators/authkit/templates/spec/models/auth_spec.rb +18 -0
  47. data/lib/generators/authkit/templates/spec/models/user_spec.rb +72 -78
  48. data/spec/rails_helper.rb +50 -0
  49. data/spec/spec_helper.rb +70 -13
  50. metadata +35 -17
  51. data/lib/generators/authkit/templates/spec/spec_helper.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a50e83ce52b25ebf0d07f9582f6d58485ff4b67
4
- data.tar.gz: 1f817df72d8bbcde3524b5da618c00ccaa48b8b3
3
+ metadata.gz: 628f696a515e94589ec7097aa85063e3c040b835
4
+ data.tar.gz: 0ac0ee2390c87494d4ebff3405379832d3f6c33a
5
5
  SHA512:
6
- metadata.gz: 78a53378ab13f476cb291fdc648114a3dc0500f8e92a541e6f8f253e4f35ce0732aafe0de35b953729ec9580f49e957cb793193405512c71fdc1e6f801e794f7
7
- data.tar.gz: bfa4d0d452bc397d2c8fc5c206182d1bbad95eece55250ad646b53faaf1d26eecf33f6285a41fa28f64178579a8ce879062f35a7093749449bbff165a0bbe1d4
6
+ metadata.gz: fa7b50d0f155153eca2da938d59a6e5c1765f7394406c577cfde13d2f161b413590dcfe9fdfd95f3f9ff3e9be9fd259c7691324b453a0fe23878ec4d30c68ba0
7
+ data.tar.gz: 2deaf4c89a911b6dc7c037c511530370823fab69d2306e07c304b30e88f14bbe42d80d42a944e66a873c257e14bdb1776d27ccd271a7939fa3479672cc16ccfe
data/README.md CHANGED
@@ -144,7 +144,6 @@ Authkit has a number of conventions and requirements that should be noted.
144
144
  * SSL expected
145
145
  * secure cookies
146
146
  * password complexity is not robust
147
- * username resrictions are not implemented
148
147
  * users do not need to confirm their email address to proceed
149
148
  * need a root route
150
149
 
@@ -158,8 +157,6 @@ There is only a minimal amount of validation on the password. Because of this us
158
157
 
159
158
  validates :password, presence: true, confirmation: true, length: {minimum: 6}, if: :password_set?
160
159
 
161
- Likewise, there are no restrictions on `username`. If you want to use this field within the URL you will need to constrain the format of the `username` field. Additionally, there may be some user names you want to explicitly disallow based on your routing setup.
162
-
163
160
  ### Confirmation not required by default
164
161
 
165
162
  By default, users can begin using the system without confirming their email address. This simplifies the onboarding process, however it means that malicious users may be operating under false pretense. You can change this by adding a check to `ApplicationController#require_login`:
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ namespace :generator do
33
33
 
34
34
  FileUtils.mkdir_p("spec/tmp")
35
35
 
36
- system "cd spec/tmp && rails new sample"
36
+ system "cd spec/tmp && rails new sample --skip-spring"
37
37
 
38
38
  # bundle
39
39
  gem_root = File.expand_path(File.dirname(__FILE__))
@@ -60,7 +60,8 @@ namespace :generator do
60
60
 
61
61
  desc "Run the #{gem_name} generator"
62
62
  task gem_name do
63
- system "cd spec/tmp/sample && rails g #{gem_name}:install --force && rake db:migrate db:test:prepare"
63
+ system "cd spec/tmp/sample && rails g #{gem_name}:install --force #{'--oauth --google' if ENV['SKIP_OAUTH'].nil?} #{'--skip-username' unless ENV['SKIP_USERNAME'].nil?} && rake db:migrate"
64
+ system "cd spec/tmp/sample && rake db:migrate RAILS_ENV=test"
64
65
  end
65
66
 
66
67
  end
@@ -1,3 +1,3 @@
1
1
  module Authkit
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -11,25 +11,66 @@ module Authkit
11
11
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
12
12
  end
13
13
 
14
+ class_option :username, type: :boolean, default: true
15
+ class_option :oauth, type: :boolean
16
+ class_option :amazon, type: :boolean
17
+ class_option :facebook, type: :boolean
18
+ class_option :flickr, type: :boolean
19
+ class_option :foursquare, type: :boolean
20
+ class_option :github, type: :boolean
21
+ class_option :google, type: :boolean
22
+ class_option :instagram, type: :boolean
23
+ class_option :linkedin, type: :boolean
24
+ class_option :paypal, type: :boolean
25
+ class_option :soundcloud, type: :boolean
26
+ class_option :tumblr, type: :boolean
27
+ class_option :twitter, type: :boolean
28
+ class_option :vimeo, type: :boolean
29
+ class_option :shopify, type: :boolean
30
+ class_option :all, type: :boolean
31
+
32
+ def self.source_root
33
+ @source_root ||= File.join(File.dirname(__FILE__), 'templates')
34
+ end
35
+
14
36
  def generate_authkit
37
+ generate_migrations
38
+ install_templates
39
+ install_routes
40
+ install_gems
41
+ end
42
+
43
+ protected
44
+
45
+ def generate_migrations
15
46
  generate_migration("create_users")
16
47
  generate_migration("add_authkit_fields_to_users")
48
+ generate_migration("create_auths") if oauth?
49
+ end
17
50
 
51
+ def ensure_destination
18
52
  # Ensure the destination structure
19
- empty_directory "app"
20
- empty_directory "app/models"
21
- empty_directory "app/forms"
22
- empty_directory "app/controllers"
23
- empty_directory "app/views"
24
- empty_directory "app/views/users"
25
- empty_directory "app/views/sessions"
26
- empty_directory "app/views/password_reset"
27
- empty_directory "app/views/password_change"
28
- empty_directory "spec"
29
- empty_directory "spec/factories"
30
- empty_directory "spec/models"
31
- empty_directory "spec/controllers"
32
- empty_directory "lib"
53
+ ["app",
54
+ "app/models",
55
+ "app/forms",
56
+ "app/controllers",
57
+ "app/helpers",
58
+ "app/views",
59
+ "app/views/users",
60
+ "app/views/sessions",
61
+ "app/views/password_reset",
62
+ "app/views/password_change",
63
+ "spec",
64
+ "spec/factories",
65
+ "spec/models",
66
+ "spec/controllers",
67
+ "lib"].each do |dir|
68
+ empty_directory dir
69
+ end
70
+ end
71
+
72
+ def install_templates
73
+ ensure_destination
33
74
 
34
75
  # Fill out some templates (for now, this is just straight copy)
35
76
  template "app/models/user.rb", "app/models/user.rb"
@@ -40,6 +81,12 @@ module Authkit
40
81
  template "app/controllers/password_change_controller.rb", "app/controllers/password_change_controller.rb"
41
82
  template "app/controllers/email_confirmation_controller.rb", "app/controllers/email_confirmation_controller.rb"
42
83
 
84
+ if oauth?
85
+ template "app/models/auth.rb", "app/models/auth.rb"
86
+ template "app/controllers/auths_controller.rb", "app/controllers/auths_controller.rb"
87
+ template "app/helpers/auths_helper.rb", "app/helpers/auths_helper.rb"
88
+ end
89
+
43
90
  template "app/forms/signup.rb", "app/forms/signup.rb"
44
91
 
45
92
  template "spec/factories/user.rb", "spec/factories/user.rb"
@@ -54,22 +101,27 @@ module Authkit
54
101
  template "spec/controllers/email_confirmation_controller_spec.rb", "spec/controllers/email_confirmation_controller_spec.rb"
55
102
 
56
103
  template "lib/email_format_validator.rb", "lib/email_format_validator.rb"
104
+ template "lib/username_format_validator.rb", "lib/username_format_validator.rb" if username?
105
+ template "lib/full_name_splitter.rb", "lib/full_name_splitter.rb"
57
106
 
58
- # Don't treat these like templates
59
- copy_file "app/views/signup/new.html.erb", "app/views/signup/new.html.erb"
60
- copy_file "app/views/users/edit.html.erb", "app/views/users/edit.html.erb"
61
- copy_file "app/views/sessions/new.html.erb", "app/views/sessions/new.html.erb"
62
- copy_file "app/views/password_reset/show.html.erb", "app/views/password_reset/show.html.erb"
63
- copy_file "app/views/password_change/show.html.erb", "app/views/password_change/show.html.erb"
107
+ template "config/initializers/omniauth.rb", "config/initializers/omniauth.rb" if oauth?
108
+
109
+ template "app/views/signup/new.html.erb", "app/views/signup/new.html.erb"
110
+ template "app/views/sessions/new.html.erb", "app/views/sessions/new.html.erb"
111
+
112
+ template "app/views/users/edit.html.erb", "app/views/users/edit.html.erb"
113
+ template "app/views/users/complete.html.erb", "app/views/users/complete.html.erb"
114
+ template "app/views/password_reset/show.html.erb", "app/views/password_reset/show.html.erb"
115
+ template "app/views/password_change/show.html.erb", "app/views/password_change/show.html.erb"
116
+ template "app/views/auths/connect.html.erb", "app/views/auths/connect.html.erb" if oauth?
64
117
 
65
118
  # We don't want to overwrite this file and we may have a protected section so we want it at the bottom
66
119
  insert_at_end_of_class "app/controllers/application_controller.rb", "app/controllers/application_controller.rb"
67
120
 
68
- # Technically, we aren't inserting this at the end of the class, but the end of the RSpec::Configure
69
- insert_at_end_of_class "spec/spec_helper.rb", "spec/spec_helper.rb"
70
-
71
121
  insert_at_end_of_file "config/initializers/filter_parameter_logging.rb", "config/initializers/filter_parameter_logging.rb"
122
+ end
72
123
 
124
+ def install_routes
73
125
  # Setup the routes
74
126
  route "get '/email/confirm/:token', to: 'email_confirmation#show', as: :confirm"
75
127
 
@@ -78,21 +130,28 @@ module Authkit
78
130
  route "post '/password/change/:token', to: 'password_change#create'"
79
131
  route "get '/password/change/:token', to: 'password_change#show', as: :password_change"
80
132
 
133
+ if oauth?
134
+ route "get '/connect', to: 'auths#connect', as: :connect"
135
+ route "get '/auth/:provider/callback', to: 'auths#callback', as: :callback"
136
+ route "get '/auth/failure', to: 'auths#failure', as: :failure"
137
+ route "get '/auth/disconnect/:id', to: 'auths#disconnect', as: :disconnect"
138
+ end
139
+
81
140
  route "post '/signup', to: 'signup#create'"
82
141
  route "get '/signup', to: 'signup#new', as: :signup"
142
+ route "get '/signup/complete', to: 'users#complete', as: :users_complete"
83
143
  route "get '/logout', to: 'sessions#destroy', as: :logout"
84
144
  route "post '/login', to: 'sessions#create'"
85
145
  route "get '/login', to: 'sessions#new', as: :login"
86
146
 
87
147
  route "patch '/account', to: 'users#update'"
88
148
  route "get '/account', to: 'users#edit', as: :user"
149
+ end
89
150
 
90
- route "resources :sessions, only: [:new, :create, :destroy]"
91
- route "resources :users, only: [:create]"
92
-
151
+ def install_gems
93
152
  # Support for has_secure_password and has_one_time_password
94
153
  gem "active_model_otp"
95
- gem "bcrypt-ruby", '~> 3.1.2'
154
+ gem "bcrypt"
96
155
 
97
156
  # RSpec needs to be in the development group to be used in generators
98
157
  gem_group :test, :development do
@@ -100,26 +159,109 @@ module Authkit
100
159
  gem "shoulda-matchers"
101
160
  gem "factory_girl_rails"
102
161
  end
162
+
163
+ if oauth?
164
+ gem 'omniauth'
165
+ gem 'omniauth-google-oauth2' if provider?(:google)
166
+ gem 'omniauth-facebook' if provider?(:facebook)
167
+ gem 'omniauth-twitter' if provider?(:twitter)
168
+ gem 'omniauth-tumblr' if provider?(:tumblr)
169
+ gem 'omniauth-soundcloud' if provider?(:soundcloud)
170
+ gem 'omniauth-shopify-oauth2' if provider?(:shopify)
171
+
172
+ # Support for google client apis
173
+ if provider?(:google)
174
+ gem 'google-api-client', :require => 'google/api_client'
175
+ gem 'faraday', '~> 0.9.0'
176
+ gem 'faraday_middleware'
177
+ end
178
+ end
103
179
  end
104
180
 
105
- def self.next_migration_number(dirname)
106
- ActiveRecord::Generators::Base.next_migration_number(dirname)
181
+ def username?
182
+ options[:username]
107
183
  end
108
184
 
109
- protected
185
+ def oauth?
186
+ options[:oauth]
187
+ end
188
+
189
+ def provider?(service)
190
+ options[service] || options[:all]
191
+ end
192
+
193
+ def providers
194
+ result = []
195
+ %w(amazon
196
+ facebook
197
+ flickr
198
+ foursquare
199
+ github
200
+ google
201
+ instagram
202
+ linkedin
203
+ paypal
204
+ soundcloud
205
+ tumblr
206
+ twitter
207
+ vimeo
208
+ shopify).each do |provider|
209
+ result << provider.to_sym if provider?(provider.to_sym)
210
+ end
211
+ result
212
+ end
213
+
214
+ def formatted_providers
215
+ {
216
+ amazon: "Amazon",
217
+ facebook: "Facebook",
218
+ flickr: "Flickr",
219
+ foursquare: "Foursquare",
220
+ github: "GitHub",
221
+ google: "Google",
222
+ instagram: "Instagram",
223
+ linkedin: "LinkedIn",
224
+ paypal: "Paypal",
225
+ soundcloud: "SoundCloud",
226
+ tumblr: "Tumblr",
227
+ twitter: "Twitter",
228
+ vimeo: "Vimeo",
229
+ shopify: "Shopify"
230
+ }
231
+ end
232
+
233
+ def font_awesome_icons
234
+ {
235
+ amazon: "amazon",
236
+ facebook: "facebook",
237
+ flickr: "flickr",
238
+ foursquare: "foursquare",
239
+ github: "github",
240
+ google: "google",
241
+ instagram: "instagram",
242
+ linkedin: "linkedin",
243
+ paypal: "paypal",
244
+ soundcloud: "soundcloud",
245
+ tumblr: "tumblr",
246
+ twitter: "twitter",
247
+ vimeo: "vimeo",
248
+ shopify: "shopify"
249
+ }
250
+ end
110
251
 
111
252
  def insert_at_end_of_file(filename, source)
112
- source = File.expand_path(find_in_source_paths(source.to_s))
113
- context = instance_eval('binding')
114
- content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
115
- insert_into_file filename, "#{content}\n", before: /\z/
253
+ insert_before filename, source, /\z/
116
254
  end
117
255
 
118
256
  def insert_at_end_of_class(filename, source)
257
+ insert_before filename, source, /end\n*\z/
258
+ end
259
+
260
+ def insert_before(filename, source, before)
119
261
  source = File.expand_path(find_in_source_paths(source.to_s))
120
262
  context = instance_eval('binding')
121
263
  content = ERB.new(::File.binread(source), nil, '-', '@output_buffer').result(context)
122
- insert_into_file filename, "#{content}\n", before: /end\n*\z/
264
+ insert_into_file filename, "#{content}\n", before: before
123
265
  end
124
266
 
125
267
  def generate_migration(filename)
@@ -129,5 +271,9 @@ module Authkit
129
271
  migration_template "db/migrate/#{filename}.rb", "db/migrate/#{filename}.rb"
130
272
  end
131
273
  end
274
+
275
+ def self.next_migration_number(dirname)
276
+ ActiveRecord::Generators::Base.next_migration_number(dirname)
277
+ end
132
278
  end
133
279
  end
@@ -37,6 +37,11 @@
37
37
 
38
38
  def require_login
39
39
  deny_user(nil, login_path) unless logged_in?
40
+ deny_user("Your account has been suspended, please contact support", login_path) if logged_in? && current_user.suspended?
41
+ end
42
+
43
+ def require_completed_login
44
+ redirect_to users_complete_path if current_user.incomplete?
40
45
  end
41
46
 
42
47
  def login(user, remember=false)
@@ -87,6 +92,7 @@
87
92
  session[:return_url] = request.fullpath
88
93
  respond_to do |format|
89
94
  format.json { render(status: 403, nothing: true) }
95
+ format.text { redirect_to(location) }
90
96
  format.html do
91
97
  flash[:error] = message || "Sorry, you must be logged in to do that"
92
98
  redirect_to(location)
@@ -0,0 +1,144 @@
1
+ # The AuthsController is used for connecting accounts only. The user must be logged
2
+ # in for the connection to work. This controller is not used for creating a new
3
+ # session.
4
+ class AuthsController < ApplicationController
5
+ before_filter :require_login, only: [:connect]
6
+ before_filter :require_login_when_connecting, only: [:callback]
7
+ before_filter :require_completed_login, only: [:disconnect]
8
+ before_filter :require_auth_hash, only: [:callback]
9
+
10
+ # Adjust scope here for particular sets of user using the session
11
+ #
12
+ # session[:google_oauth_scope] = 'userinfo.email, userinfo.profile, adsense, adsense.readonly'
13
+ #
14
+ # You can also reset it to the default using nil
15
+ def connect
16
+ end
17
+
18
+ def callback
19
+ # If we are not connecting we want to logout any existing user
20
+ logout unless connecting?
21
+
22
+ if connecting?
23
+ if auth && auth.user == current_user
24
+ # This is an auth that is already connected to this user (success, noop)
25
+ redirect_to settings_path
26
+ elsif auth && auth.user_id != current_user.id
27
+ # This is an auth that is connected to another user (error)
28
+ deny_user("Sorry, this account is already connected to another account", settings_path)
29
+ else
30
+ # Success, add the auth and redirect to settings
31
+ @auth ||= current_user.auths.build(auth_params)
32
+
33
+ if current_user.save
34
+ redirect_to account_path
35
+ else
36
+ flash[:error] = "Sorry, there was an error connecting this account"
37
+ redirect_to accounts_path
38
+ end
39
+ end
40
+ else
41
+ # Could have a check here for login/sign up action to be explicit
42
+ #
43
+ # If login and auth does not exist, confirm that they want to signup (not attach)
44
+ # If signup and auth exists, confirm that they have selected the right account (already exists)
45
+ if auth
46
+ login(auth.user)
47
+ redirect_to account_path
48
+ elsif auth_email.present? && User.where(email: auth_email.downcase).count > 0
49
+ deny_user("Sorry, the email address associated with this account is already connected to an existing user", signup_path)
50
+ else
51
+ @signup = Signup.new_with_oauth(auth_params, {kind: @kind})
52
+
53
+ if signup.save
54
+ login(signup.user)
55
+ redirect_to account_path
56
+ else
57
+ flash[:error] = "Sorry, there was an error connecting this account (#{@signup.errors.full_messages.to_sentence})"
58
+ redirect_to signup_path
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ def disconnect
65
+ # TODO: you may want to change this lookup to use uid and provider
66
+ @auth = current_user.auths.where(params[:id])
67
+ @auth.destroy
68
+ respond_to do |format|
69
+ format.json { head :no_content }
70
+ format.html {
71
+ redirect_to accounts_path
72
+ }
73
+ end
74
+ end
75
+
76
+ def failure
77
+ flash[:error] = "Sorry, there was an error connecting this account: #{params[:message]}"
78
+ if connecting?
79
+ redirect_to settings_path
80
+ elsif signing_up?
81
+ redirect_to signup_path
82
+ else
83
+ redirect_to login_path
84
+ end
85
+ end
86
+
87
+ protected
88
+
89
+ def signup
90
+ return @signup if defined?(@signup)
91
+ end
92
+
93
+ def auth
94
+ return @auth if defined?(@auth)
95
+ @auth = Auth.where(uid: auth_hash.uid, provider: auth_hash.provider).first
96
+ end
97
+
98
+ def auth_hash
99
+ @auth_hash ||= request.env["omniauth.auth"]
100
+ end
101
+
102
+ def auth_email
103
+ auth_hash.info.try(:email) || auth_hash.extra.try(:raw_info).try(:verified_email)
104
+ end
105
+
106
+ def auth_params
107
+ HashWithIndifferentAccess.new({
108
+ uid: auth_hash.uid,
109
+ provider: auth_hash.provider,
110
+ email: auth_hash.info.try(:email),
111
+ verified_email: auth_hash.extra.try(:raw_info).try(:verified_email),
112
+ token: auth_hash.credentials.try(:token),
113
+ token_expires_at: auth_hash.credentials.try(:expires_at),
114
+ refresh_token: auth_hash.credentials.try(:refresh_token),
115
+ secret_token: auth_hash.credentials.try(:secret_token),
116
+ env: auth_hash.to_json
117
+ })
118
+ end
119
+
120
+ def require_auth_hash
121
+ if auth_hash.blank? || auth_hash.uid.blank? || auth_hash.provider.blank?
122
+ deny_user("Sorry, there was an error connecting this account", root_path)
123
+ end
124
+ end
125
+
126
+ def require_login_when_connecting
127
+ if connecting? && !logged_in?
128
+ deny_user("Sorry, you must be logged in to connect this account", login_path)
129
+ end
130
+ end
131
+
132
+ def connecting?
133
+ env['omniauth.params']['connect'].present?
134
+ end
135
+
136
+ def logging_in?
137
+ env['omniauth.params']['login'].present?
138
+ end
139
+
140
+ def signing_up?
141
+ env['omniauth.params']['signup'].present?
142
+ end
143
+ end
144
+