[英]HTTP Basic Auth in Rails while disabling other authentication
我有一个使用Devise和Authy进行用户身份验证的应用程序,并且我想使用模型( ApiUser
)中的一组单独用户添加API访问,目前仅使用基本身份验证。 我的控制器中有以下代码:
class Api::SomethingsController < ApplicationController
load_and_authorize_resource param_method: :something_params
skip_authorize_resource
skip_authorization_check
skip_before_filter :verify_authenticity_token
skip_before_action :authenticate_user!
skip_before_action :enable_authy
before_filter :api_authenticate
private
def api_authenticate
authenticate_with_http_basic do |userid, password|
user = ApiUser.find_by(userid: userid, passwd: password)
user
end
end
但是,没有进行身份验证-我得到的结果完全没有身份验证。
我究竟做错了什么??
请改用authenticate_or_request_with_http_basic
。
def api_authenticate
authenticate_or_request_with_http_basic("Somethings Authentication") do |userid, password|
user = ApiUser.find_by(userid: userid, passwd: password)
user
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.