devise_token_auth 0.1.37 → 0.1.38

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_token_auth might be problematic. Click here for more details.

Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/app/controllers/devise_token_auth/application_controller.rb +24 -0
  4. data/app/controllers/devise_token_auth/concerns/set_user_by_token.rb +21 -4
  5. data/app/controllers/devise_token_auth/confirmations_controller.rb +1 -1
  6. data/app/controllers/devise_token_auth/omniauth_callbacks_controller.rb +7 -5
  7. data/app/controllers/devise_token_auth/passwords_controller.rb +9 -10
  8. data/app/controllers/devise_token_auth/registrations_controller.rb +13 -13
  9. data/app/controllers/devise_token_auth/sessions_controller.rb +3 -3
  10. data/app/controllers/devise_token_auth/token_validations_controller.rb +3 -3
  11. data/app/models/devise_token_auth/concerns/user.rb +18 -35
  12. data/app/models/devise_token_auth/concerns/user_omniauth_callbacks.rb +28 -0
  13. data/config/initializers/devise.rb +1 -1
  14. data/config/locales/de.yml +1 -1
  15. data/config/locales/ja.yml +47 -0
  16. data/config/locales/nl.yml +31 -0
  17. data/lib/devise_token_auth/controllers/helpers.rb +6 -0
  18. data/lib/devise_token_auth/engine.rb +9 -1
  19. data/lib/devise_token_auth/rails/routes.rb +3 -2
  20. data/lib/devise_token_auth/version.rb +1 -1
  21. data/lib/generators/devise_token_auth/USAGE +1 -1
  22. data/lib/generators/devise_token_auth/install_generator.rb +3 -1
  23. data/lib/generators/devise_token_auth/templates/devise_token_auth.rb +12 -1
  24. data/test/controllers/custom/custom_omniauth_callbacks_controller_test.rb +1 -1
  25. data/test/controllers/demo_group_controller_test.rb +14 -1
  26. data/test/controllers/demo_user_controller_test.rb +54 -5
  27. data/test/controllers/devise_token_auth/confirmations_controller_test.rb +10 -6
  28. data/test/controllers/devise_token_auth/omniauth_callbacks_controller_test.rb +1 -1
  29. data/test/controllers/devise_token_auth/passwords_controller_test.rb +3 -3
  30. data/test/controllers/devise_token_auth/registrations_controller_test.rb +9 -9
  31. data/test/controllers/devise_token_auth/sessions_controller_test.rb +15 -0
  32. data/test/controllers/overrides/passwords_controller_test.rb +1 -1
  33. data/test/dummy/app/controllers/custom/confirmations_controller.rb +1 -1
  34. data/test/dummy/app/controllers/custom/omniauth_callbacks_controller.rb +1 -1
  35. data/test/dummy/app/controllers/custom/passwords_controller.rb +3 -3
  36. data/test/dummy/app/controllers/custom/registrations_controller.rb +2 -2
  37. data/test/dummy/app/controllers/custom/sessions_controller.rb +2 -2
  38. data/test/dummy/app/controllers/custom/token_validations_controller.rb +1 -1
  39. data/test/dummy/app/controllers/demo_user_controller.rb +13 -0
  40. data/test/dummy/app/controllers/overrides/registrations_controller.rb +1 -1
  41. data/test/dummy/config/application.rb +2 -0
  42. data/test/dummy/config/routes.rb +2 -0
  43. data/test/dummy/tmp/generators/app/models/user.rb +7 -0
  44. data/test/dummy/tmp/generators/config/initializers/devise_token_auth.rb +48 -0
  45. data/test/dummy/tmp/generators/db/migrate/20160711201448_devise_token_auth_create_users.rb +54 -0
  46. data/test/lib/devise_token_auth/url_test.rb +19 -23
  47. data/test/test_helper.rb +1 -1
  48. metadata +16 -11
  49. data/test/dummy/tmp/generators/app/views/devise/mailer/confirmation_instructions.html.erb +0 -5
  50. data/test/dummy/tmp/generators/app/views/devise/mailer/reset_password_instructions.html.erb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cb47a5fba41d7ebd8bc1d0c8f3ca0efb1895de7
4
- data.tar.gz: f249fd363679cb78330361b84b73538c897cf148
3
+ metadata.gz: aa39458371b7528fd21f448db0ee9925c85925c0
4
+ data.tar.gz: a0eaf377f37b1a5c36ff93df23effaee5747ebb5
5
5
  SHA512:
6
- metadata.gz: 70f0be0bdf639d61b7f508d402b13c859250439fd11d9d18332b72c1e8a3a676ed151b90743cb43984e31b14237ad385e333f4672f3cbdc968043e50f09de611
7
- data.tar.gz: e53a3f7c326d34c265fe99087441d299f19c711e408f62cae81a486258613c2a40b7eecbb6e9b42b9aa83f09d6bc02d2fc78d30d38d9116ba842f060217796cf
6
+ metadata.gz: 0cd833a8afc253f5c72622ef1536a10d0fc527ff830c089e3b6c8ce76c909dcd0a084d3c7cc6b563d663c009308043e3b2d8128c60d35dd5e58ba3df4f355d9f
7
+ data.tar.gz: 29f59819d0a882b8dc83c9ac78f172b8b8e7f20b80b4c361d3867ddff89295be122e0ced3d82e7387f0eaa7ffdfedb911daf685552e272f24d83bfc1bc564cc1
data/README.md CHANGED
@@ -139,7 +139,7 @@ The following routes are available for use by your client. These routes live rel
139
139
  | / | DELETE | Account deletion. This route will destroy users identified by their **`uid`** and **`auth_token`** headers. |
140
140
  | / | PUT | Account updates. This route will update an existing user's account settings. The default accepted params are **`password`** and **`password_confirmation`**, but this can be customized using the [`devise_parameter_sanitizer`](https://github.com/plataformatec/devise#strong-parameters) system. If **`config.check_current_password_before_update`** is set to `:attributes` the **`current_password`** param is checked before any update, if it is set to `:password` the **`current_password`** param is checked only if the request updates user password. |
141
141
  | /sign_in | POST | Email authentication. Requires **`email`** and **`password`** as params. This route will return a JSON representation of the `User` model on successful login along with the `access-token` and `client` in the header of the response. |
142
- | /sign_out | DELETE | Use this route to end the user's current session. This route will invalidate the user's authentication token. |
142
+ | /sign_out | DELETE | Use this route to end the user's current session. This route will invalidate the user's authentication token. You must pass in **`uid`**, **`client`**, and **`access-token`** in the request headers. |
143
143
  | /:provider | GET | Set this route as the destination for client authentication. Ideally this will happen in an external window or popup. [Read more](#omniauth-authentication). |
144
144
  | /:provider/callback | GET/POST | Destination for the oauth2 provider's callback uri. `postMessage` events containing the authenticated user's data will be sent back to the main client window from this page. [Read more](#omniauth-authentication). |
145
145
  | /validate_token | GET | Use this route to validate tokens on return visits to the client. Requires **`uid`**, **`client`**, and **`access-token`** as params. These values should correspond to the columns in your `User` table of the same names. |
@@ -166,6 +166,7 @@ The following settings are available for configuration in `config/initializers/d
166
166
  | **`redirect_whitelist`** | `nil` | As an added security measure, you can limit the URLs to which the API will redirect after email token validation (password reset, email confirmation, etc.). This value should be an array containing exact matches to the client URLs to be visited after validation. |
167
167
  | **`enable_standard_devise_support`** | `false` | By default, only Bearer Token authentication is implemented out of the box. If, however, you wish to integrate with legacy Devise authentication, you can do so by enabling this flag. NOTE: This feature is highly experimental! |
168
168
  | **`remove_tokens_after_password_reset`** | `false` | By default, old tokens are not invalidated when password is changed. Enable this option if you want to make passwords updates to logout other devices. |
169
+ | **`default_callbacks`** | `true` | By default User model will include the `DeviseTokenAuth::Concerns::UserOmniauthCallbacks` concern, which has `email`, `uid` validations & `uid` synchronization callbacks. |
169
170
 
170
171
 
171
172
  Additionally, you can configure other aspects of devise by manually creating the traditional devise.rb file at `config/initializers/devise.rb`. Here are some examples of what you can do in this file:
@@ -781,7 +782,7 @@ Yes! But you will need to enable the support use separate routes for standard De
781
782
  #### config/initializers/devise_token_auth.rb
782
783
  ~~~ruby
783
784
  DeviseTokenAuth.setup do |config|
784
- # enable_standard_devise_support = false
785
+ # config.enable_standard_devise_support = false
785
786
  end
786
787
  ~~~
787
788
 
@@ -844,7 +845,7 @@ These measures are taken by default when using this gem.
844
845
 
845
846
  ## About batch requests
846
847
 
847
- By default, the API should update the auth token for each request ([read more](#about-token-management)). But sometimes it's neccessary to make several concurrent requests to the API, for example:
848
+ By default, the API should update the auth token for each request ([read more](#about-token-management)). But sometimes it's necessary to make several concurrent requests to the API, for example:
848
849
 
849
850
  #####Batch request example
850
851
  ~~~javascript
@@ -2,9 +2,24 @@ module DeviseTokenAuth
2
2
  class ApplicationController < DeviseController
3
3
  include DeviseTokenAuth::Concerns::SetUserByToken
4
4
 
5
+ def resource_data(opts={})
6
+ response_data = opts[:resource_json] || @resource.as_json
7
+ if is_json_api
8
+ response_data['type'] = @resource.class.name.parameterize
9
+ end
10
+ response_data
11
+ end
12
+
13
+ def resource_errors
14
+ return @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
15
+ end
16
+
5
17
  protected
6
18
 
7
19
  def params_for_resource(resource)
20
+ devise_parameter_sanitizer.instance_values['permitted'][resource].each do |type|
21
+ params[type.to_s] ||= request.headers[type.to_s] unless request.headers[type.to_s].nil?
22
+ end
8
23
  devise_parameter_sanitizer.instance_values['permitted'][resource]
9
24
  end
10
25
 
@@ -17,5 +32,14 @@ module DeviseTokenAuth
17
32
 
18
33
  mapping.to
19
34
  end
35
+
36
+ def is_json_api
37
+ return false unless defined?(ActiveModel::Serializer)
38
+ return ActiveModel::Serializer.setup do |config|
39
+ config.adapter == :json_api
40
+ end if ActiveModel::Serializer.respond_to?(:setup)
41
+ return ActiveModelSerializers.config.adapter == :json_api
42
+ end
43
+
20
44
  end
21
45
  end
@@ -23,10 +23,15 @@ module DeviseTokenAuth::Concerns::SetUserByToken
23
23
  # no default user defined
24
24
  return unless rc
25
25
 
26
+ #gets the headers names, which was set in the initialize file
27
+ uid_name = DeviseTokenAuth.headers_names[:'uid']
28
+ access_token_name = DeviseTokenAuth.headers_names[:'access-token']
29
+ client_name = DeviseTokenAuth.headers_names[:'client']
30
+
26
31
  # parse header for values necessary for authentication
27
- uid = request.headers['uid'] || params['uid']
28
- @token = request.headers['access-token'] || params['access-token']
29
- @client_id = request.headers['client'] || params['client']
32
+ uid = request.headers[uid_name] || params[uid_name]
33
+ @token ||= request.headers[access_token_name] || params[access_token_name]
34
+ @client_id ||= request.headers[client_name] || params[client_name]
30
35
 
31
36
  # client_id isn't required, set to 'default' if absent
32
37
  @client_id ||= 'default'
@@ -56,7 +61,12 @@ module DeviseTokenAuth::Concerns::SetUserByToken
56
61
  user = uid && rc.find_by_uid(uid)
57
62
 
58
63
  if user && user.valid_token?(@token, @client_id)
59
- sign_in(:user, user, store: false, bypass: true)
64
+ # sign_in with bypass: true will be deprecated in the next version of Devise
65
+ if self.respond_to? :bypass_sign_in
66
+ bypass_sign_in(user, scope: :user)
67
+ else
68
+ sign_in(:user, user, store: false, bypass: true)
69
+ end
60
70
  return @resource = user
61
71
  else
62
72
  # zero all values previously set values
@@ -74,6 +84,10 @@ module DeviseTokenAuth::Concerns::SetUserByToken
74
84
  @client_id = nil unless @used_auth_by_token
75
85
 
76
86
  if @used_auth_by_token and not DeviseTokenAuth.change_headers_on_each_request
87
+ # should not append auth header if @resource related token was
88
+ # cleared by sign out in the meantime
89
+ return if @resource.reload.tokens[@client_id].nil?
90
+
77
91
  auth_header = @resource.build_auth_header(@token, @client_id)
78
92
 
79
93
  # update the response header
@@ -84,6 +98,9 @@ module DeviseTokenAuth::Concerns::SetUserByToken
84
98
  # Lock the user record during any auth_header updates to ensure
85
99
  # we don't have write contention from multiple threads
86
100
  @resource.with_lock do
101
+ # should not append auth header if @resource related token was
102
+ # cleared by sign out in the meantime
103
+ return if @used_auth_by_token && @resource.tokens[@client_id].nil?
87
104
 
88
105
  # determine batch request status after request processing, in case
89
106
  # another processes has updated it during that processing
@@ -17,7 +17,7 @@ module DeviseTokenAuth
17
17
 
18
18
  @resource.save!
19
19
 
20
- yield if block_given?
20
+ yield @resource if block_given?
21
21
 
22
22
  redirect_to(@resource.build_auth_url(params[:redirect_url], {
23
23
  token: token,
@@ -2,7 +2,7 @@ module DeviseTokenAuth
2
2
  class OmniauthCallbacksController < DeviseTokenAuth::ApplicationController
3
3
 
4
4
  attr_reader :auth_params
5
- skip_before_action :set_user_by_token
5
+ skip_before_action :set_user_by_token, raise: false
6
6
  skip_after_action :update_auth_header
7
7
 
8
8
  # intermediary route for successful omniauth authentication. omniauth does
@@ -11,8 +11,9 @@ module DeviseTokenAuth
11
11
 
12
12
  # derive target redirect route from 'resource_class' param, which was set
13
13
  # before authentication.
14
- devise_mapping = request.env['omniauth.params']['resource_class'].underscore.gsub("/", "_").to_sym
15
- redirect_route = "#{request.protocol}#{request.host_with_port}/#{Devise.mappings[devise_mapping].fullpath}/#{params[:provider]}/callback"
14
+ devise_mapping = [request.env['omniauth.params']['namespace_name'],
15
+ request.env['omniauth.params']['resource_class'].underscore.gsub('/', '_')].compact.join('_')
16
+ redirect_route = "#{request.protocol}#{request.host_with_port}/#{Devise.mappings[devise_mapping.to_sym].fullpath}/#{params[:provider]}/callback"
16
17
 
17
18
  # preserve omniauth info for success route. ignore 'extra' in twitter
18
19
  # auth response to avoid CookieOverflow.
@@ -37,7 +38,7 @@ module DeviseTokenAuth
37
38
 
38
39
  @resource.save!
39
40
 
40
- yield if block_given?
41
+ yield @resource if block_given?
41
42
 
42
43
  render_data_or_redirect('deliverCredentials', @auth_params.as_json, @resource.as_json)
43
44
  end
@@ -142,7 +143,8 @@ module DeviseTokenAuth
142
143
  # necessary for access to devise_parameter_sanitizers
143
144
  def devise_mapping
144
145
  if omniauth_params
145
- Devise.mappings[omniauth_params['resource_class'].underscore.to_sym]
146
+ Devise.mappings[[omniauth_params['namespace_name'],
147
+ omniauth_params['resource_class'].underscore].compact.join('_').to_sym]
146
148
  else
147
149
  request.env['devise.mapping']
148
150
  end
@@ -47,7 +47,7 @@ module DeviseTokenAuth
47
47
  @error_status = 400
48
48
 
49
49
  if @resource
50
- yield if block_given?
50
+ yield @resource if block_given?
51
51
  @resource.send_reset_password_instructions({
52
52
  email: @email,
53
53
  provider: 'email',
@@ -94,7 +94,7 @@ module DeviseTokenAuth
94
94
  @resource.allow_password_change = true;
95
95
 
96
96
  @resource.save!
97
- yield if block_given?
97
+ yield @resource if block_given?
98
98
 
99
99
  redirect_to(@resource.build_auth_url(params[:redirect_url], {
100
100
  token: token,
@@ -126,7 +126,7 @@ module DeviseTokenAuth
126
126
  if @resource.send(resource_update_method, password_resource_params)
127
127
  @resource.allow_password_change = false
128
128
 
129
- yield if block_given?
129
+ yield @resource if block_given?
130
130
  return render_update_success
131
131
  else
132
132
  return render_update_error
@@ -160,14 +160,15 @@ module DeviseTokenAuth
160
160
  def render_create_error_not_allowed_redirect_url
161
161
  render json: {
162
162
  status: 'error',
163
- data: @resource.as_json,
163
+ data: resource_data,
164
164
  errors: [I18n.t("devise_token_auth.passwords.not_allowed_redirect_url", redirect_url: @redirect_url)]
165
- }, status: 403
165
+ }, status: 422
166
166
  end
167
167
 
168
168
  def render_create_success
169
169
  render json: {
170
170
  success: true,
171
+ data: resource_data,
171
172
  message: I18n.t("devise_token_auth.passwords.sended", email: @email)
172
173
  }
173
174
  end
@@ -207,17 +208,15 @@ module DeviseTokenAuth
207
208
  def render_update_success
208
209
  render json: {
209
210
  success: true,
210
- data: {
211
- user: @resource,
212
- message: I18n.t("devise_token_auth.passwords.successfully_updated")
213
- }
211
+ data: resource_data,
212
+ message: I18n.t("devise_token_auth.passwords.successfully_updated")
214
213
  }
215
214
  end
216
215
 
217
216
  def render_update_error
218
217
  return render json: {
219
218
  success: false,
220
- errors: @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
219
+ errors: resource_errors
221
220
  }, status: 422
222
221
  end
223
222
 
@@ -110,54 +110,54 @@ module DeviseTokenAuth
110
110
  def render_create_error_missing_confirm_success_url
111
111
  render json: {
112
112
  status: 'error',
113
- data: @resource.as_json,
113
+ data: resource_data,
114
114
  errors: [I18n.t("devise_token_auth.registrations.missing_confirm_success_url")]
115
- }, status: 403
115
+ }, status: 422
116
116
  end
117
117
 
118
118
  def render_create_error_redirect_url_not_allowed
119
119
  render json: {
120
120
  status: 'error',
121
- data: @resource.as_json,
121
+ data: resource_data,
122
122
  errors: [I18n.t("devise_token_auth.registrations.redirect_url_not_allowed", redirect_url: @redirect_url)]
123
- }, status: 403
123
+ }, status: 422
124
124
  end
125
125
 
126
126
  def render_create_success
127
127
  render json: {
128
128
  status: 'success',
129
- data: @resource.as_json
129
+ data: resource_data
130
130
  }
131
131
  end
132
132
 
133
133
  def render_create_error
134
134
  render json: {
135
135
  status: 'error',
136
- data: @resource.as_json,
137
- errors: @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
138
- }, status: 403
136
+ data: resource_data,
137
+ errors: resource_errors
138
+ }, status: 422
139
139
  end
140
140
 
141
141
  def render_create_error_email_already_exists
142
142
  render json: {
143
143
  status: 'error',
144
- data: @resource.as_json,
144
+ data: resource_data,
145
145
  errors: [I18n.t("devise_token_auth.registrations.email_already_exists", email: @resource.email)]
146
- }, status: 403
146
+ }, status: 422
147
147
  end
148
148
 
149
149
  def render_update_success
150
150
  render json: {
151
151
  status: 'success',
152
- data: @resource.as_json
152
+ data: resource_data
153
153
  }
154
154
  end
155
155
 
156
156
  def render_update_error
157
157
  render json: {
158
158
  status: 'error',
159
- errors: @resource.errors.to_hash.merge(full_messages: @resource.errors.full_messages)
160
- }, status: 403
159
+ errors: resource_errors
160
+ }, status: 422
161
161
  end
162
162
 
163
163
  def render_update_error_user_not_found
@@ -42,7 +42,7 @@ module DeviseTokenAuth
42
42
 
43
43
  sign_in(:user, @resource, store: false, bypass: false)
44
44
 
45
- yield if block_given?
45
+ yield @resource if block_given?
46
46
 
47
47
  render_create_success
48
48
  elsif @resource and not (!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
@@ -62,7 +62,7 @@ module DeviseTokenAuth
62
62
  user.tokens.delete(client_id)
63
63
  user.save!
64
64
 
65
- yield if block_given?
65
+ yield user if block_given?
66
66
 
67
67
  render_destroy_success
68
68
  else
@@ -108,7 +108,7 @@ module DeviseTokenAuth
108
108
 
109
109
  def render_create_success
110
110
  render json: {
111
- data: @resource.token_validation_response
111
+ data: resource_data(resource_json: @resource.token_validation_response)
112
112
  }
113
113
  end
114
114
 
@@ -6,19 +6,19 @@ module DeviseTokenAuth
6
6
  def validate_token
7
7
  # @resource will have been set by set_user_token concern
8
8
  if @resource
9
- yield if block_given?
9
+ yield @resource if block_given?
10
10
  render_validate_token_success
11
11
  else
12
12
  render_validate_token_error
13
13
  end
14
14
  end
15
15
 
16
- protected
16
+ protected
17
17
 
18
18
  def render_validate_token_success
19
19
  render json: {
20
20
  success: true,
21
- data: @resource.token_validation_response
21
+ data: resource_data(resource_json: @resource.token_validation_response)
22
22
  }
23
23
  end
24
24
 
@@ -27,20 +27,14 @@ module DeviseTokenAuth::Concerns::User
27
27
  serialize :tokens, JSON
28
28
  end
29
29
 
30
- validates :email, presence: true, email: true, if: Proc.new { |u| u.provider == 'email' }
31
- validates_presence_of :uid, if: Proc.new { |u| u.provider != 'email' }
32
-
33
- # only validate unique emails among email registration users
34
- validate :unique_email_user, on: :create
30
+ if DeviseTokenAuth.default_callbacks
31
+ include DeviseTokenAuth::Concerns::UserOmniauthCallbacks
32
+ end
35
33
 
36
34
  # can't set default on text fields in mysql, simulate here instead.
37
35
  after_save :set_empty_token_hash
38
36
  after_initialize :set_empty_token_hash
39
37
 
40
- # keep uid in sync with email
41
- before_save :sync_uid
42
- before_create :sync_uid
43
-
44
38
  # get rid of dead tokens
45
39
  before_save :destroy_expired_tokens
46
40
 
@@ -76,6 +70,7 @@ module DeviseTokenAuth::Concerns::User
76
70
  if pending_reconfirmation?
77
71
  opts[:to] = unconfirmed_email
78
72
  end
73
+ opts[:redirect_url] ||= DeviseTokenAuth.default_confirm_success_url
79
74
 
80
75
  send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)
81
76
  end
@@ -182,14 +177,6 @@ module DeviseTokenAuth::Concerns::User
182
177
  updated_at: Time.now
183
178
  }
184
179
 
185
- max_clients = DeviseTokenAuth.max_number_of_devices
186
- while self.tokens.keys.length > 0 and max_clients < self.tokens.keys.length
187
- oldest_token = self.tokens.min_by { |cid, v| v[:expiry] || v["expiry"] }
188
- self.tokens.delete(oldest_token.first)
189
- end
190
-
191
- self.save!
192
-
193
180
  return build_auth_header(token, client_id)
194
181
  end
195
182
 
@@ -201,12 +188,20 @@ module DeviseTokenAuth::Concerns::User
201
188
  # must be cast as string or headers will break
202
189
  expiry = self.tokens[client_id]['expiry'] || self.tokens[client_id][:expiry]
203
190
 
191
+ max_clients = DeviseTokenAuth.max_number_of_devices
192
+ while self.tokens.keys.length > 0 and max_clients < self.tokens.keys.length
193
+ oldest_token = self.tokens.min_by { |cid, v| v[:expiry] || v["expiry"] }
194
+ self.tokens.delete(oldest_token.first)
195
+ end
196
+
197
+ self.save!
198
+
204
199
  return {
205
- "access-token" => token,
206
- "token-type" => "Bearer",
207
- "client" => client_id,
208
- "expiry" => expiry.to_s,
209
- "uid" => self.uid
200
+ DeviseTokenAuth.headers_names[:"access-token"] => token,
201
+ DeviseTokenAuth.headers_names[:"token-type"] => "Bearer",
202
+ DeviseTokenAuth.headers_names[:"client"] => client_id,
203
+ DeviseTokenAuth.headers_names[:"expiry"] => expiry.to_s,
204
+ DeviseTokenAuth.headers_names[:"uid"] => self.uid
210
205
  }
211
206
  end
212
207
 
@@ -221,7 +216,6 @@ module DeviseTokenAuth::Concerns::User
221
216
 
222
217
  def extend_batch_buffer(token, client_id)
223
218
  self.tokens[client_id]['updated_at'] = Time.now
224
- self.save!
225
219
 
226
220
  return build_auth_header(token, client_id)
227
221
  end
@@ -239,21 +233,10 @@ module DeviseTokenAuth::Concerns::User
239
233
 
240
234
  protected
241
235
 
242
- # only validate unique email among users that registered by email
243
- def unique_email_user
244
- if provider == 'email' and self.class.where(provider: 'email', email: email).count > 0
245
- errors.add(:email, I18n.t("errors.messages.already_in_use"))
246
- end
247
- end
248
-
249
236
  def set_empty_token_hash
250
237
  self.tokens ||= {} if has_attribute?(:tokens)
251
238
  end
252
239
 
253
- def sync_uid
254
- self.uid = email if provider == 'email'
255
- end
256
-
257
240
  def destroy_expired_tokens
258
241
  if self.tokens
259
242
  self.tokens.delete_if do |cid, v|
@@ -270,7 +253,7 @@ module DeviseTokenAuth::Concerns::User
270
253
 
271
254
  if should_remove_old_tokens
272
255
  latest_token = self.tokens.max_by { |cid, v| v[:expiry] || v["expiry"] }
273
- self.tokens = {latest_token.first => latest_token.last}
256
+ self.tokens = { latest_token.first => latest_token.last }
274
257
  end
275
258
  end
276
259