【问题标题】:Error: redirect_uri_mismatch when using omniauth-google-oauth2错误:使用omniauth-google-oauth2 时的redirect_uri_mismatch
【发布时间】:2016-08-01 00:22:01
【问题描述】:

我已使用 Facebook 登录。我现在正在尝试使用 Google 登录。

我得到错误:redirect_uri_mismatch,我不知道为什么。

我看到有人说要使用omniauth-oauth2 v. 1.3.1 所以我是。

我的路线文件包括:

gem 'omniauth-facebook'
gem 'omniauth-google-oauth2', '~> 0.4.1'
gem 'omniauth-oauth2', '~> 1.3.1'

我的 omniauth.rb 文件是:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_APP_ID'], ENV['FACEBOOK_SECRET'], info_fields: 'email,first_name,last_name'
  provider :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"],
  {
    :name => "google",
    :scope => "email, profile, plus.me, http://gdata.youtube.com",
    :prompt => "select_account",
    :image_aspect_ratio => "square",
    :image_size => 50
  }
end

我收到了错误信息

The redirect URI in the request, http://localhost:3000/auth/google/callback, does not match the ones authorized for the OAuth client

并复制 uri,然后进入 google api 的凭据页面,然后将确切的 uri 添加为授权重定向 URI。

任何帮助将不胜感激。

【问题讨论】:

标签: ruby-on-rails oauth


【解决方案1】:

console.developers.google.com。输入您应用的网址加

“/auth/google_oauth2/callback” 

在“授权重定向 URIs 字段中。所以应该是:

http://localhost:3000/auth/google_oauth2/callback

【讨论】:

  • 当我这样做时,我得到:没有路由匹配 [GET] "/auth/google_oauth2"
  • 我的 routes.rb 包括:get '/auth/:provider/callback', to: 'sessions#create_omniauth'
  • 从终端,我可以运行“curl localhost:3000/auth/google_oauth2/callback”并找到该路由。但是如果我在没有 /callback 的情况下尝试它,它不会。这几乎就像谷歌没有发回 /callback。
  • 好吧,我修好了。我做了你说的@HasmukhRathod,即使我以前试过。它没有解决它,但后来我尝试了omniauth.rb 文件中的google_oauth2 部分。它修复了它。我最终发现问题出在 :name => "google" 问题上。当我按照 Hasmukh Rathod 所说的去做,然后去掉 name 键时,它起作用了!万岁!
  • @atarihomestar 发布此评论作为答案并接受该评论。
猜你喜欢
  • 2021-06-22
  • 2020-06-13
  • 2014-04-29
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 2012-12-18
  • 2012-04-23
  • 1970-01-01
相关资源
最近更新 更多