我来接这个
策略::OAuth2::CallbackError at /auth/google/callback csrf_detected CSRF检测到
我的代码:
require 'sinatra'
require "sinatra/json"
require "sinatra/config_file"
require 'omniauth-oauth2'
require 'omniauth-google-oauth2'
use Rack::Logger
config_file "config/app_config.yml"
use Rack::Session::Cookie, secret: '5fb7w345y3489f523y4h'
configure do
enable :sessions
end
use OmniAuth::Builder do
provider :google_oauth2, settings.google[:client_id], settings.google[:secret],
{
:scope => "userinfo.profile",
:access_type => "offline",
:prompt => "select_account consent",
:name => "google"
}
end
get '/list' do
json get_list
end
get '/' do
%Q|<a href='/auth/google'>Sign in with Google</a>|
end
get '/auth/:name/callback' do
@auth = request.env['omniauth.auth']
@auth.inspect
end
我的回调将返回代码和状态。
发布于 2014-05-19 13:49:36
有同样的问题
(google_oauth2)回调阶段启动。 (google_oauth2)身份验证失败!csrf_detected: OmniAuth::策略:OAuth2::CallbackError,已检测到csrf_detected \ CSRF
最后,OmniauthOAuth2更新引入了"state“param有一个强制字段。
有些人建议使用provider_ignores_state: true,但这是个坏主意,因为它引入了csrf缺陷
我想我们将不得不降级到以前的版本,以保持google_oauth2工作。
发布于 2014-07-21 10:09:30
当/config/initializer/session_store.rb
中定义的域与google控制台中定义的源/重定向_uri不同时,rails就会出现这个问题。
MyApp::Application.config.session_store :cookie_store, key: '_app_session', domain: 'my_app.com'
删除域旁或在双方使用相同的域修复了问题。
发布于 2014-08-04 05:04:38
如果使用devise.rb,则需要跳过额外的omniauth.rb初始化程序文件,只需在初始化器/devise.rb中添加config.provider "KEY“、”config.provider“,然后继续实现。
https://stackoverflow.com/questions/22386149
复制相似问题