3

アプリケーションにGoogleFederatedLogin(OpenID)のみを使用するようにアプリを移動しています(すべてにGoogleアプリを使用しており、そこでユーザー管理を組み合わせる方が簡単だと感じています)。ログインしてユーザーを作成することはできますが、今ではセキュリティについて考えています...

ユーザーがログインすると、「ログイン」ボタンしかありません。他には何もありません。サイトドメインはハードコーディングされており(SITE_DOMAINが下に表示されています)、ユーザーは通常のGoogleログインページにリダイレクトされます。

コードは次のとおりです。

    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プラグインと基本的なrubyopenidgem(googleアプリ用のruby-openid-apps-discovery gemを使用)を使用しています

4

1 に答える 1

1

omn​​iauthのおかげで、これははるかに簡単になりました。

于 2010-12-17T03:35:11.200 に答える