我正在使用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" %>
我哪里错了?
答案 0 :(得分:0)
尝试将令牌添加到omniauth初始化程序中:
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