1

ユーザーが Google OpenID を使用して Rails アプリケーションにサインインできるようにしたいと考えています。だから私はこれらの宝石を持っています

gem 'omniauth'
gem 'omniauth-openid'
gem 'devise'

config/initializers/omniauth.rb

require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :open_id, :store => OpenID::Store::Filesystem.new('/tmp'), :name => 'google', 
    :identifier => 'https://www.google.com/accounts/o8/id', :require => 'omniauth-openid'
end

OmniAuth.config.on_failure = Proc.new do |env|
    OmniAuth::FailureEndpoint.new(env).redirect_to_failure 

終わり

リンク先のページもあります

<% if current_user %>
  Welcome <%= current_user.name %>!
  <%= link_to "Sign Out", signout_path %>
<% else %>
  <%= link_to "Sign in with Google", "/auth/google" %>

<% end %>

Google のログイン ページにリダイレクトされたときに [許可] をクリックすると、正しくログインしたにもかかわらず、何らかの理由で... /auth/failure?message=invalid_credentials&strategy=googleにリダイレクトされます。

Webrick からのログは次のとおりです。

Started GET "/auth/google" for 127.0.0.1 at 2012-12-20 12:45:13 +0700
(google) Callback phase initiated.
Error attempting to use stored discovery information: OpenID::TypeURIMismatch
Attempting discovery to verify endpoint
Performing discovery on https://www.google.com/accounts/o8/id?id=323221212143243243
WARNING: making https request to https://www.google.com/accounts/o8/id?id=2121212143243243243243 without verifying server certificate; no CA path was specified.
(google) Callback phase initiated.
(google) Authentication failure! invalid_credentials encountered.


Started GET "/auth/google/callback?_method=post&openid.ns= .... very long string" for 127.0.0.1 at 2012-12-20 12:45:18 +0700


Started GET "/auth/failure?message=invalid_credentials&strategy=google" for 127.0.0.1 at 2012-12-20 12:45:18 +0700

私は何を間違えましたか?

4

1 に答える 1

4

あなたは言うごとに何も悪いことをしていません。残念ながら、OpenID からの Google の応答は非常に長い URL です。webrick が処理できる 256 文字を超えている限り。

次のように、gemfile に別のサーバーを追加する場合:

gem 'thin'

次に、次のようにサーバーを起動します。

rails s thin

その後、Google 経由でログインしても問題ないことがわかります。

于 2012-12-20T07:51:57.070 に答える