2009-12-31 30 views
0

Warp Drive是將整個Rails應用程序打包到Gem中以便在其他Rails應用程序中使用的好方法。我已經讓Warp Drive爲我正在創建的博客引擎工作。只有一個問題 - Authlogic OpenID身份驗證失敗。我創建了bare-bones OpenID example application。我可以編譯成寶石,沒有任何問題:Authlogic/OpenID身份驗證失敗使用扭曲驅動器

$ warpify 
$ rake warp_drive:compile 

然後我安裝我的系統上編譯的寶石。創建一個空白的Rails項目,我跑了:

$ install_warp_drive rails-openid 

你可以get this project here

在我的空白Rails的項目,我需要通過environment.rb配置寶石(我可能這個做了錯誤的方式):

config.gem "authlogic" 
config.gem "authlogic-oid", :lib => "authlogic_openid" 
config.gem "ruby-openid", :lib => "openid" 

要獲得空白Rails應用程序的工作,我跑耙分貝:遷移,然後通過控制檯添加一個用戶:openid_identifier字段設置爲我控制的字段。到現在爲止還挺好。但是,試圖創建一個新的會話失敗,此錯誤:

Processing UserSessionsController#create (for 127.0.0.1 at 2009-12-31 11:35:59) [POST] 
    Parameters: {"commit"=>"Login", "user_session"=>{"openid_identifier"=>"richdev.myopenid.com"}, "authenticity_token"=>"BcsIKNpumqZrTV/bdSLQ6szBvq6kpaAIxJRmYgxySLU="} 
    OpenIdAuthentication::Association Load (0.3ms) SELECT * FROM "open_id_authentication_associations" WHERE ("open_id_authentication_associations"."server_url" = 'http://www.myopenid.com/server') 
    Generated checkid_setup request to http://www.myopenid.com/server with assocication {HMAC-SHA1}{4b3cf228}{mWlzhg==} 
    Redirected to http://www.myopenid.com/server?openid.assoc_handle=%7BHMAC-SHA1%7D%7B4b3cf228%7D%7BmWlzhg%3D%3D%7D&openid.ax.mode=fetch_request&openid.identity=http%3A%2F%2Frichdev.myopenid.com%2F&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Flocalhost%3A3001%2Fuser_sessions%2Fcreate%3Ffor_session%3D1%26_method%3Dpost%26open_id_complete%3D1%26openid1_claimed_id%3Dhttp%253A%252F%252Frichdev.myopenid.com%252F%26rp_nonce%3D2009-12-31T19%253A35%253A59ZUEd2eN&openid.trust_root=http%3A%2F%2Flocalhost%3A3001%2F 
    Completed in 15ms (DB: 0) | 302 Found [http://localhost/user_sessions] 


    Processing ApplicationController#index (for 127.0.0.1 at 2009-12-31 11:36:00) [POST] 
    Parameters: {"openid.mode"=>"id_res", "openid.return_to"=>"http://localhost:3001/user_sessions/create?for_session=1&_method=post&open_id_complete=1&openid1_claimed_id=http%3A%2F%2Frichdev.myopenid.com%2F&rp_nonce=2009-12-31T19%3A35%3A59ZUEd2eN", "openid.sig"=>"l+tfFAmeKsskHKlOYRoZF7yHM7Q=", "rp_nonce"=>"2009-12-31T19:35:59ZUEd2eN", "openid.op_endpoint"=>"http://www.myopenid.com/server", "for_session"=>"1", "openid.response_nonce"=>"2009-12-31T19:36:00ZBhX5fE", "openid1_claimed_id"=>"http://richdev.myopenid.com/", "openid.identity"=>"http://richdev.myopenid.com/", "open_id_complete"=>"1", "openid.assoc_handle"=>"{HMAC-SHA1}{4b3cf228}{mWlzhg==}", "openid.signed"=>"assoc_handle,identity,mode,op_endpoint,response_nonce,return_to,signed"} 

    ActionController::MethodNotAllowed (Only get, put, and delete requests are allowed.): 


    Rendered rescues/_trace (96.3ms) 
    Rendered rescues/_request_and_response (0.5ms) 
    Rendering rescues/layout (method_not_allowed) 

這個問題似乎重定向從OpenID提供商,在這一點的ApplicationController#指數被召回過程中發生,而不是UserSessionsController#創建。我不確定這是OpenID問題還是Warp Drive問題。

如何將Authlogic/OpenID應用程序作爲Warp Drive Gem進行捆綁並使驗證成功運行?

更新:爲user_session添加顯式資源定義可修復此問題。在routes.rb中:

map.resources :user_sessions 

不知道爲什麼,而這似乎並不需要任何其他控制器。

回答

0

兩個事情的來龍去脈:

map.resources:在應用程序中的routes.rb user_sessions

  • 刪除默認路由

    1. 在routes.rb中添加一個明確的USER_SESSION資源定義使用經編驅動寶石。在routes.rb中

  • 0

    刪除默認路由

     
        map.connect ':controller/:action/:id' 
        map.connect ':controller/:action/:id.:format' 
    

    解決了一個可怕的路由問題,即在經驅動的資源路由:

     
    map.resources :users, :member => {:activate => [:post, :get]} 
    

    創建一個URL:/用戶/: id/activate(。:format)

    但是對該URL的HTTP請求導致:action和:id獲得反向當傳遞給控制器​​時(如同被解釋爲默認URL一樣)。例如

     
    Parameters = {"action"=>"123456", "id"=>"activate", "controller"=>"users"} 
    

    不漂亮。刪除warp驅動器或客戶端應用程序中的默認路由。雖然,在客戶端應用中似乎更安全。