You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/lib/auth_with_token_strategy.rb

22 lines
464 B

# frozen_string_literal: true
class AuthWithTokenStrategy < Devise::Strategies::Base
def valid?
request.headers['X-Auth-Token'].present?
end
def authenticate!
sha256 = Digest::SHA256.hexdigest(request.headers['X-Auth-Token'])
user = User.joins(:access_token).find_by(access_token: { sha256: })
if user
success!(user)
else
fail!('Invalid token')
end
rescue JWT::VerificationError
fail!('Invalid token')
end
end