简体   繁体   English

带有 devise 身份验证失败的谷歌omniauth rails

[英]google omniauth rails with devise authentication failure

I want add omniauth with Google on my Rails app but i have error after redirection我想在我的 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"
}

I saw errors about bad redirection uri but not "bad request"我看到了有关错误重定向 uri 的错误,但没有看到“错误请求”

My redirection uri in google console我在谷歌控制台中的重定向 uri

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

My route我的路线

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

Gemfile宝石文件

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

devise devise

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

my link我的链接

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

Check your google developer account where you created the credentials.检查您创建凭据的谷歌开发者帐户。 there should be a field named redirect URL where you should place the correct URL.应该有一个名为重定向 URL 的字段,您应该在其中放置正确的 URL。 This URL was used to redirect the user from modal opened on login with google.此 URL 用于将用户从使用 google 登录时打开的模式重定向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM