加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 使用Omniauth和Google检测到“CSRF”

发布时间:2020-12-16 22:11:34 所属栏目:百科 来源:网络整理
导读:我得到这个 OmniAuth::Strategies::OAuth2::CallbackError at /auth/google/callback csrf_detected | CSRF detected 我的代码: require 'sinatra'require "sinatra/json"require "sinatra/config_file"require 'omniauth-oauth2'require 'omniauth-google-
我得到这个

OmniAuth::Strategies::OAuth2::CallbackError at /auth/google/callback
csrf_detected | CSRF detected

我的代码:

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

我的回调是返回代码和状态.

解决方法

有同样的问题

(google_oauth2) Callback phase initiated.
(google_oauth2)
Authentication failure! csrf_detected:
OmniAuth::Strategies::OAuth2::CallbackError,csrf_detected | CSRF
detected

最后一个Omniauth-oauth2更新引入了“state”param有一个必填字段.

有些人建议使用provider_ignores_state:true,但这是一个坏主意,因为它引入了csrf缺陷

猜测我们必须降级到以前的版本,以保持google_oauth2的工作.

在https://github.com/intridea/omniauth-oauth2/issues/58发行

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读