3

我正在移动一个应用程序以仅将 Google 联合登录 (OpenID) 用于应用程序(我们使用谷歌应用程序来处理所有事情,并且觉得在那里结合用户管理会更容易)。虽然我可以成功登录并创建用户,但我现在的想法是安全......

当用户登录时,我只有一个“登录”按钮 - 没有别的。站点域是硬编码的(其中 SITE_DOMAIN 出现在下面),并且用户被重定向到典型的谷歌登录页面。

这是代码:

    def create
    open_id_authentication
  end

  protected

  def open_id_authentication
    openid_url = 'https://www.google.com/accounts/o8/site-xrds?hd=SITE_DOMAIN'
    authenticate_with_open_id(openid_url, 
                              :required => ['http://axschema.org/contact/email',
                                            'http://axschema.org/namePerson/first',
                                            'http://axschema.org/namePerson/last']) do |result, identity_url, registration|
      case result.status
      when :missing
        failed_login "Sorry, the OpenID server couldn't be found"
      when :invalid
        failed_login "Sorry, but this does not appear to be a valid OpenID"
      when :canceled
        failed_login "OpenID verification was canceled"
      when :failed
        failed_login "Sorry, the OpenID verification failed"
      when :successful
        if @current_user = User.find_by_id_url(identity_url)
          if @current_user.login_from(request.env['REMOTE_ADDR'])
            successful_login
          else
            failed_login "Your OpenID profile registration failed: " + @current_user.errors.full_messages.to_sentence
          end
        else
          ax_response = OpenID::AX::FetchResponse.from_success_response(request.env[Rack::OpenID::RESPONSE])
          @current_user = User.login_create(ax_response, identity_url, request.env['REMOTE_ADDR'])
          successful_login
        end
      end
    end
  end

成功登录后,我只需将用户保存到会话中...

session[:current_user] = @current_user

...并在应用程序控制器中使用简单的 current_user 方法...

  def current_user
    return session[:current_user] if defined?(session[:current_user])
  end

我主要关心的是安全性。OpenIDAuthentication 正在使用内存存储,总体而言,这似乎有点太容易实现(在阅读了大量文档之后)。基本测试表明这很好用,但我很紧张。:)

有什么想法吗?

我正在使用 open_id_authentication 插件和基本的 ruby​​ openid gem(与 ruby​​-openid-apps-discovery gem 用于谷歌应用程序)

4

1 回答 1

1

多亏了omniauth,这现在变得容易多了。

于 2010-12-17T03:35:11.200 回答