2016-02-12 206 views
0

我有一个使用Devise和Authy进行用户身份验证的应用程序,我想在模型(ApiUser)中为一组单独的用户添加API访问,现在只需使用Basic验证。我在我的控制器中有以下代码:禁用其他身份验证的HTTP基本身份验证

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   

但是,没有进行身份验证 - 我得到的结果根本没有身份验证。

我在做什么错?

回答

0

改为使用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 
+0

作品 - 谢谢! –