代码之家  ›  专栏  ›  技术社区  ›  Rich Apodaca

Authlogic/OpenID身份验证使用Warp Drive失败

  •  0
  • Rich Apodaca  · 技术社区  · 15 年前

    Warp Drive

    我创造了一个 bare-bones OpenID example application

    $ warpify
    $ rake warp_drive:compile
    

    然后我在我的系统上安装了编译好的gem。创建空白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应用程序,我运行RAKE DB:MigRead,然后通过控制台,我添加了一个用户:一个OpenIDL标识符字段设置为我控制的一个。到现在为止,一直都还不错。但尝试创建新会话失败,出现以下错误:

        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#index,而不是UserSessionController#create。我不确定这是OpenID问题还是Warp驱动器问题。

    如何将Authlogic/OpenID应用程序捆绑为Warp Drive Gem,并成功进行身份验证?

    更新:为用户会话添加显式资源定义修复了该问题。在routes.rb中:

    map.resources :user_sessions
    

    不知道为什么,其他任何控制器似乎都不需要这样做。

    2 回复  |  直到 15 年前
        1
  •  0
  •   Rich Apodaca    15 年前

    有两件事奏效了:

    1. 在routes.rb中添加显式用户会话资源定义:

    2. 使用warp drive gem删除应用程序routes.rb中的默认路由。

        2
  •  0
  •   Kevin Kohrt    14 年前

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

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

    已创建URL:/users/:id/激活(:格式)

    但对该URL的HTTP请求导致:action和:id在传递给控制器时发生反转(好像被解释为默认URL)。例如

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

    推荐文章