Skip to content

Commit

Permalink
Tweak to allow correct use of not changing headers on each request
Browse files Browse the repository at this point in the history
  • Loading branch information
Uelb committed Jun 25, 2016
1 parent 572e9b1 commit 7c19493
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ def update_auth_header

# Generate new client_id with existing authentication
@client_id = nil unless @used_auth_by_token
return if response.code.to_i >= 300

if @used_auth_by_token and not DeviseTokenAuth.change_headers_on_each_request
# should not append auth header if @resource related token was
# cleared by sign out in the meantime
return if @resource.reload.tokens[@client_id].nil?
return if @resource.reload.tokens[@client_id].nil? && @client_id != 'default'

auth_header = @resource.build_auth_header(@token, @client_id)

Expand All @@ -100,8 +101,7 @@ def update_auth_header
@resource.with_lock do
# should not append auth header if @resource related token was
# cleared by sign out in the meantime
return if @used_auth_by_token && @resource.tokens[@client_id].nil?

return if @client_id != 'default' && @used_auth_by_token && @resource.tokens[@client_id].nil?
# determine batch request status after request processing, in case
# another processes has updated it during that processing
@is_batch_request = is_batch_request?(@resource, @client_id)
Expand Down
4 changes: 4 additions & 0 deletions app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def build_auth_header(token, client_id='default')

# client may use expiry to prevent validation request if expired
# must be cast as string or headers will break
# binding.pry
if self.tokens[client_id].nil? && client_id == 'default' || token.nil?
return create_new_auth_token
end
expiry = self.tokens[client_id]['expiry'] || self.tokens[client_id][:expiry]

max_clients = DeviseTokenAuth.max_number_of_devices
Expand Down

0 comments on commit 7c19493

Please sign in to comment.