2011-09-20 40 views
1

谷歌我的Rails 3.0.9应用程序, 在我sessions_controller我有认证通过OpenID的

def open_id_authentication(domain=nil) 
    domain = "" if domain.nil? 
    complete_identity_url = IDENTITY_URL + domain 
    authenticate_with_open_id(complete_identity_url, OPENID_OPTS) do |openid_result, identity_url, registration| 
    if openid_result.successful? 
     matches = /\/a\/(.*)\/o8/.match(params["openid.op_endpoint"]) 
     google_domain = matches[1] if matches[1] 
     if valid_account?(google_domain) 
     account = Account.find_by_google_domain(google_domain) 
     session[:account_id] = account.id 
     self.current_user = User.openid_registration(registration, identity_url, account.id) 
     else 
     flash[:error] = t('flash.session.domain_not_registered') 
     redirect_to accounts_path 
     return false 
    end 

     redirect_back_or_default(THIS_path) 
    else 
     flash[:error] = t('flash.open_id.authentication_failed') 
     redirect_to accounts_path 
    end 
    end 
end 

的Gemfile

gem 'ruby-openid', '2.1.8' 
gem 'ruby-openid-apps-discovery', '1.2.0' 
gem 'open_id_authentication', '1.0.0' 

我收到提示行

matches = /\/a\/(.*)\/o8/.match(params["openid.op_endpoint"]) 

因为params不包含这样的密钥。

之前,该应用程序是Rails 2.3.14和三个列出的宝石是插件。它运行良好。 有人发过这样的东西,请帮忙。

谢谢!

回答

1

我解决了通过更换

matches = /\/a\/(.*)\/o8/.match(params["openid.op_endpoint"]) 

通过

matches = /\/a\/(.*)\/o8/.match(request.env[Rack::OpenID::RESPONSE].endpoint.server_url)