问题描述
全部!
一些背景:我正在使用 OmniAuth 开发 rails 应用程序。我们也使用设计,但我们没有在设计初始值设定项中使用任何 OmniAuth 配置,只是一个独立的 OmniAuth 初始值设定项。当用户尝试连接他们的 Google Analytics 配置文件时,我们偶尔会遇到 CookieOverflow 异常问题。为此,我们使用了 omniauth-google-oauth2。
我们代码的基本(隐私混淆)概述:
# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :developer unless Rails.env.production?
provider :google_oauth2,ENV['GOOGLE_CLIENT_ID'],ENV['GOOGLE_SECRET'],{
callback_path: "/i/auth/google/callback",scope: "email,profile,youtube.readonly,yt-analytics.readonly,analytics.readonly",name: 'google_analytics',prompt: 'select_account',verify_iss: false
}
end
# config/routes.rb
# Skipping other irrelevant code
scope module: 'users',path: 'i',as: 'users' do
get '/auth/:provider/callback',to: 'sessions#create'
end
class Users::SessionsController < Users::UsersBaseController
def create
if auth_hash.provider == 'google_analytics'
profile = GoogleAnalyticsProfile.create(
token: auth_hash.credentials.token,token_expires_at: auth_hash.credentials.expires_at,refresh_token: auth_hash.credentials.refresh_token,email: auth_hash.info.email,first_name: auth_hash.info.first_name,last_name: auth_hash.info.last_name,user: current_user
)
SomeWorker.perform_async(current_user.id)
# Excluding other providers for brevity
elsif auth_hash.provider == 'some_other_provider'
# do stuff
end
redirect_to (request.env['omniauth.origin'] || some_application_path(current_user,section: :some_section)),notice: "Successfully connected your #{auth_hash.provider.titleize} account!"
end
protected
def auth_hash
request.env['omniauth.auth']
end
end
我正在尝试弄清楚为什么我们会出现这些溢出。它只发生在某些用户身上。我假设这是因为 某些东西 在会话中持久化了 Auth Hash,尤其是那个庞大的“额外”部分,但我不知道是什么。我们的身份验证会话控制器中没有任何内容明确设置任何会话信息,我在 OmniAuth 或 omniauth-google-oauth2 源代码中没有看到任何设置会话中疯狂的内容,只是引用信息(来自我记得的)。我们还为其他一些提供商使用了其他一些 OmniAuth 策略,但只有 Google Analytics 会导致 CookieOverflow 异常。我还调试了会话的内容,包括我们的会话控制器和 the middleware code 中计算会话大小的本地断点。我无法在手头的任何 Google 配置文件上触发 cookie 溢出异常,但会话的内容似乎从未在此过程中的任何时候包含任何 OmniAuth 信息,它从未包含在 4096 字节限制附近的任何地方。到目前为止,我得到的最大容量约为 1600 字节。
我们使用 Sentry 来捕获生产中的异常,虽然源 URL 被标识为为 google 配置的 Oauth 回调 URL,但堆栈跟踪中没有任何内容指向我们的控制器、设计、OmniAuth 或任何其他 gem 或我们写的代码。全部都是 Puma -> Rails Engine -> 机架/中间件代码,其中散布着一些天窗调用。所以,我有点不知所措。我不知道是什么导致了会话膨胀或如何防止它...
我知道 there are docs out there 说要使用设计配置和特殊控制器而不是 OmniAuth 初始值设定项,您可以在其中明确设置会话信息,但这些步骤似乎也旨在通过配置登录这些来源,即使用 Google 登录应用程序。我们的目的不是这样做,只是授予对用户 Google Analytics(分析)个人资料的基本访问权限。
我是否误解或遗漏了什么?任何有关如何调试/解决的线索或提示将不胜感激!
更新: 堆栈跟踪似乎是正确的,它在进入我们的代码之前就在中间件的某个地方爆炸了。我向控制器添加了一个 rescue_from
以进行一些额外的日志记录以了解发生了什么,尽管错误继续在 Sentry 中被捕获,但新的 rescue_from
并没有受到影响。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)