Rails3 omniauth google для аутентификации при возврате идентификатора пользователя - PullRequest
2 голосов
/ 01 декабря 2011

Моя интеграция с Omniauth работает при локальной разработке, но не работает для google при подготовке.

require 'omniauth/openid'
require 'openid/store/memcache'

Rails.application.config.middleware.use OmniAuth::Builder do
  OmniAuth.config.full_host = "http://xx.xx.xxx/"

  # dedicated openid
   provider :open_id, OpenID::Store::Memcache.new(Dalli::Client.new), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'

end

Я получаю следующее сообщение об ошибке:

Started GET "/ auth / fail? Message = invalid_credentials"для 58.71.19.178 в 2011-12-01 02:22:20 +0000 Обработка ErrorsController # маршрутизация как HTML Параметры: {" message "=>" invalid_credentials "," a "=>" auth / fail "} Предоставлено общедоступным/404.html (0,1 мс) Завершено 404 Не найдено в 1 мс (Просмотров: 0,6 мс | ActiveRecord: 0,0 мс)

Кроме того, ip в for не совпадает в моем OmniAuth.config.full_host, может быть,быть причиной проблемы?

Ответы [ 2 ]

1 голос
/ 02 декабря 2011

Виновным было то, что apache отправлял и возвращал на разных ips

Этот патч обезьяны исправил проблему.

module OmniAuth
  module Strategies
    # OmniAuth strategy for connecting via OpenID. This allows for connection
    # to a wide variety of sites, some of which are listed [on the OpenID website](http://openid.net/get-an-openid/).
    class OpenID
      protected
      def callback_url
        uri = URI.parse(request.url)
        uri.path += '/callback'

        # by KirylP: to overcome hosting subdomain forwarding to rails port        
        uri.port = '' if request.env.has_key? 'HTTP_X_FORWARDED_SERVER'

        uri.to_s
      end
    end
  end
end

module Rack
  class OpenID
    SERVER_PORT_TO_AVOID = 12002

    private
    def realm_url(req)
      url = req.scheme + "://"
      url << req.host

      scheme, port = req.scheme, req.port
      if scheme == "https" && port != 443 ||
          scheme == "http" && port != 80
        url << ":#{port}" if port != SERVER_PORT_TO_AVOID # KirylP
      end

      url
    end
  end
end

module OpenID
  class Consumer
    def complete(query, current_url)
      message = Message.from_post_args(query)

      current_url.sub!(":#{Rack::OpenID::SERVER_PORT_TO_AVOID}", '') # KirylP

      mode = message.get_arg(OPENID_NS, 'mode', 'invalid')
      begin
        meth = method('complete_' + mode)
      rescue NameError
        meth = method(:complete_invalid)
      end
      response = meth.call(message, current_url)
      cleanup_last_requested_endpoint
      if [SUCCESS, CANCEL].member?(response.status)
        cleanup_session
      end
      return response
    end    
  end
end
0 голосов
/ 01 декабря 2011

У меня была похожая проблема.Похоже, ваша аутентификация Google не проходит (это может быть по разным причинам - неверные учетные данные или отказ в доступе пользователя), поэтому вы получаете обратный вызов / auth / fail - и затем вы получаете 404.

Реализован ли маршрутза /auth/failure в ваших маршрутах .rb?В моем текущем проекте:

в routes.rb

match '/auth/failure', :to => 'sessions#failure'

в sessions_controller

def failure
   redirect_to session[:return_uri] || root_path, alert: "Sorry, we were not able to    authenticate you using your chosen sign on method"
end
...