【问题标题】:Google OpenID strategy is not working in RailsGoogle OpenID 策略在 Rails 中不起作用
【发布时间】:2012-12-20 05:54:27
【问题描述】:

我想让用户使用 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

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby openid omniauth google-openid


    【解决方案1】:

    你说的并没有做错什么。不幸的是,Google 对 OpenID 的响应是一个非常长的 URL。只要超过 webrick 可以处理的 256 个字符。

    如果您在 gemfile 中添加另一个服务器,例如:

    gem 'thin'
    

    然后像这样启动服务器:

    rails s thin
    

    那么你应该会发现通过 google 登录就可以了。

    【讨论】:

    • 那么艾伦,当你在瘦身下跑的时候,日志现在说什么?
    • 和webrick说的一样。
    猜你喜欢
    • 2021-07-04
    • 2013-03-30
    • 2023-04-07
    • 2021-06-24
    • 2012-04-06
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多