Skip to content

Commit

Permalink
fix(concern): fix BCrypt namespacing after Devise 3.5.2 update. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
booleanbetrayal committed Aug 29, 2015
1 parent bf2cc1b commit bf0d19b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/models/devise_token_auth/concerns/user.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require 'bcrypt'

module DeviseTokenAuth::Concerns::User
extend ActiveSupport::Concern

def self.tokens_match?(token_hash, token)
@token_equality_cache ||= {}

key = "#{token_hash}/#{token}"
result = @token_equality_cache[key] ||= (BCrypt::Password.new(token_hash) == token)
result = @token_equality_cache[key] ||= (::BCrypt::Password.new(token_hash) == token)
if @token_equality_cache.size > 10000
@token_equality_cache = {}
end
Expand Down Expand Up @@ -147,7 +149,7 @@ def token_can_be_reused?(token, client_id)
Time.parse(updated_at) > Time.now - DeviseTokenAuth.batch_request_buffer_throttle and

# ensure that the token is valid
BCrypt::Password.new(last_token) == token
::BCrypt::Password.new(last_token) == token
)
end

Expand All @@ -157,7 +159,7 @@ def create_new_auth_token(client_id=nil)
client_id ||= SecureRandom.urlsafe_base64(nil, false)
last_token ||= nil
token = SecureRandom.urlsafe_base64(nil, false)
token_hash = BCrypt::Password.create(token)
token_hash = ::BCrypt::Password.create(token)
expiry = (Time.now + DeviseTokenAuth.token_lifespan).to_i

if self.tokens[client_id] and self.tokens[client_id]['token']
Expand Down

0 comments on commit bf0d19b

Please sign in to comment.