gpt4 book ai didi

ruby-on-rails - Oauth 2 "redirect_uri_mismatch: { "错误”: "redirect_uri_mismatch" }"in rails

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:36 27 4
gpt4 key购买 nike

我正在使用 oauth2 gem 进行谷歌登录验证。我的代码看起来像

omniauth.rb

OmniAuth.config.logger = Rails.logger
require "omniauth-google-oauth2"
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, 'secret-client-id', 'secret-number', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end

我的routes.rb

  get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')

我的观点

 <%= link_to "Sign in with Google", "/auth/google_oauth2", id: "sign_in" %>

我在这个页面之后得到这个 URL enter image description here

enter image description here

我哪里错了?

最佳答案

尝试向 omniauth 初始化程序添加 token :

Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, "id", "secret", {
client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}},
scope: 'email profile',
access_type: 'online',
setup: (lambda do |env|
request = Rack::Request.new(env)
env['omniauth.strategy'].options['token_params'] = {:redirect_uri => 'http://.../auth/google_oauth2/callback'}
end)
}
end

关于ruby-on-rails - Oauth 2 "redirect_uri_mismatch: { "错误”: "redirect_uri_mismatch" }"in rails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33354095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com