谷歌一直将我重定向到旧的OAuth2回调网址

时间:2015-02-21 15:04:32

标签: ruby-on-rails ruby ruby-on-rails-4 oauth-2.0 google-api

我正在使用gem 'omniauth-google-oauth2'。我无法在Google上进行身份验证,因为它说回调网址与我在谷歌控制台为该项目设置的回调网址不同。

#routes.rb
Rails.application.routes.draw do
  devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }

#config/initializers/omniauth.rb
Rails.configuration.google_analytics = YAML.load_file(Rails.root.join('config', 'google_analytics.yml'))[Rails.env]
Rails.application.config.middleware.use OmniAuth::Builder do
  provider(:google_oauth2, Rails.configuration.google_analytics['client_id'], Rails.configuration.google_analytics['client_secret'], 
    { scope: 'userinfo.profile, userinfo.email, analytics', access_type: 'offline', prompt: 'consent' }
  )
end


# app/controllers/users/omniauth_callbacks_controller.rb
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def google_oauth2
    #.....

谷歌的回复详情:

    from_login=1
    response_type=code
    scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/analytics
    access_type=offline
    redirect_uri=http://my_app.herokuapp.com/users/oauth/google_oauth2/callback
    state=fsfdsfds
    as=-fdsfds
    pli=1
    client_id=fdsfds-fdsfdsfd.apps.googleusercontent.com
    prompt=consent
    authuser=1
    hl=en

所以问题是google console的回调网址设置为http://my_app.herokuapp.com/users/omniauth_callbacks/google_oauth2,并且在应用程序中根据所有设置它是相同的,但谷歌一直将我重定向到http://my_app.herokuapp.com/users/oauth/google_oauth2/callback出于某种原因。

0 个答案:

没有答案