As part of an API application I am working on there is authentication required to make calls. I am attempting the most basic call with a curl command including the header basic authentication. In the authenticate block, which is called when a user attempts to access any secure calls, there is the following code:
unless credential = cache.fetch("credential::#{auth.credentials[0]}:#{Digest::MD5.hexdigest(auth.credentials[1])}")
sql = "SELECT * FROM credentials WHERE username = '#{auth.credentials[0]}' AND passwd_hashed = '#{Digest::MD5.hexdigest(auth.credentials[1])}'"
ActiveRecord::Base.connection.execute(sql).each do |row|
credential = row
end
end
For some reason this is not returning any results. I have taken the sql outputted from this block and ran it in postgres where it returns the desired row. I have tested my environment to make sure I am connecting to the correct database which I am. Beyond that I am not sure what the problem is or how to diagnose it. Any help would be appreciated.
Any suggestions as to how I could return an error from this block would also help greatly. Tried adding exception handling but cant seem to get the syntax correct.
Can you run in rails console? Have you result?
result = ActiveRecord::Base.connection.execute(sql)
result.to_a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With