2016-02-12 209 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

作品 - 謝謝! –