我想让用户使用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 %>
当我被重定向到Google登录页面时,我点击“允许”,然后我将被重定向回... / auth / failure?message = invalid_credentials&amp; strategy = google for尽管我已正确登录,但有些原因。
这是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
我做错了什么?
答案 0 :(得分:4)
每说一句你没有做错什么。不幸的是,Google对OpenID的回复是一个非常长的网址。很长一段时间,它超过了webrick可以处理的256个字符。
如果您在gemfile中添加其他服务器,例如:
gem 'thin'
然后像这样启动服务器:
rails s thin
然后您应该发现通过谷歌登录就可以了。