Ruby on rails Rails使用\u http\u basic对\u或\u请求\u进行身份验证总是返回完成的401
我尝试使用Ruby on rails Rails使用\u http\u basic对\u或\u请求\u进行身份验证总是返回完成的401,ruby-on-rails,curb,Ruby On Rails,Curb,我尝试使用authenticate\u或\u request\u with_http\u basic保护我的API服务,我尝试了GET和POST方法,它返回true,因此我可以从API存储/获取数据,但当我尝试更新值时,rails总是返回false,终端如下所示: Filter chain halted as :authenticate rendered or redirected Completed 401 Unauthorized in 3ms (ActiveRecord: 0.0ms)
authenticate\u或\u request\u with_http\u basic
保护我的API服务,我尝试了GET和POST方法,它返回true,因此我可以从API存储/获取数据,但当我尝试更新值时,rails总是返回false,终端如下所示:
Filter chain halted as :authenticate rendered or redirected
Completed 401 Unauthorized in 3ms (ActiveRecord: 0.0ms)
我想知道为什么它总是无法在update/PUT/PATCH方法上进行身份验证
以下是验证我的API服务的完整方法:
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