我想让用户使用 Google OpenID 登录我的 Rails 应用程序。所以我有这些宝石
gem 'omniauth'
gem 'omniauth-openid'
gem 'devise'
配置/初始化程序/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 %>
当我被重定向到谷歌登录页面时,我点击“允许”,我被重定向回 ... /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
我做错什么了?