【问题标题】:google omniauth rails with devise authentication failure谷歌omniauth rails与设计身份验证失败
【发布时间】:2021-04-22 16:41:17
【问题描述】:

我想在我的 Rails 应用上使用 Google 添加omniauth,但重定向后出现错误

ERROR -- omniauth: (google_oauth2) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: Bad Request
{
  "error": "redirect_uri_mismatch",
  "error_description": "Bad Request"
}

我看到了有关错误重定向 uri 的错误,但没有看到“错误请求”

我在谷歌控制台中的重定向 uri

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

我的路线

devise_for :clients, controllers: { omniauth_callbacks: 'clients/omniauth_callbacks' }

宝石文件

gem 'omniauth-oauth2'
gem 'omniauth-google-oauth2'
gem "omniauth-linkedin-oauth2"
gem 'omniauth-rails_csrf_protection', '~> 1.0'

设计

  config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], access_type: "online"

我的链接

<%= link_to "Sign in with Google", client_google_oauth2_omniauth_authorize_path, method: :post %>

【问题讨论】:

    标签: ruby-on-rails devise omniauth omniauth-google-oauth2


    【解决方案1】:

    检查您创建凭据的 Google 开发者帐户。应该有一个名为重定向 URL 的字段,您应该在其中放置正确的 URL。此 URL 用于将用户从使用 google 登录时打开的模式重定向。

    【讨论】:

    • 我已经在凭据中添加了重定向网址
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 2014-07-20
    • 2018-07-02
    • 2021-12-06
    • 2017-08-27
    相关资源
    最近更新 更多