2011-06-05 115 views
2

我一直試圖通過一個簡單的get來獲得驗證的一整天。設計和身份驗證

class ApiController < ApplicationController 
    def signin 
    warden.authenticate(params[:email], params[:password]) 
    render :json => current_user.to_json 
    end 
end 

當我打這個的東西,如http://localhost:3000/api/signin?email=theemailaddress&password=thepassword

我得到的消息:「無效的戰略theemailaddress」,這裏是堆棧:

warden (1.0.4) lib/warden/proxy.rb:323:in `_fetch_strategy' 
warden (1.0.4) lib/warden/proxy.rb:307:in `block in _run_strategies_for' 
warden (1.0.4) lib/warden/proxy.rb:306:in `each' 
warden (1.0.4) lib/warden/proxy.rb:306:in `_run_strategies_for' 
warden (1.0.4) lib/warden/proxy.rb:279:in `_perform_authentication' 
warden (1.0.4) lib/warden/proxy.rb:90:in `authenticate' 
actionpack (3.0.7) lib/action_controller/metal/implicit_render.rb:5:in `send_action' 

什麼我需要得到像這會怎麼樣?

回答

2

您需要定義一個自定義監獄戰略並檢查請求標頭。看什麼I did here

+0

除了這樣做,我不得不指定戰略召喚時的戰略。 「warden.authenticate!(:loginstrategy)」 – Steven 2011-06-05 05:12:48

+0

注意到一旦你得到用戶,你可以調用user.validate_password?(密碼) – Steven 2011-06-05 05:13:46

+0

這也是有用的。在我的情況下,我沒有使用密碼,因爲代理處理了所有預認證,所以我需要用戶名來創建/獲取帳戶。 – David 2011-06-05 05:15:47