I'm trying to secure my API service using authenticate_or_request_with_http_basic
, i have tried in GET and POST method it return true, so i can store/fetch data from API but when i'm trying to update value, the rails always return false and the terminal looks like this:
Filter chain halted as :authenticate rendered or redirected
Completed 401 Unauthorized in 3ms (ActiveRecord: 0.0ms)
I was wondering why it always failed to authenticate on update/PUT/PATCH method ?
here is the complete method to authenticate my API service:
def authenticate
puts "here 1"
if authenticate_or_request_with_http_basic('Qontak') do |username, password|
puts "here 2"
@user = User.find_by(public_key: username, private_key: password)
end
else
puts "here 3"
render json: {message: 'Unauthorized'}
end
puts "here 4"
end