oauth-2.0 Spring和中间件冲突?

svdrlsy4  于 2022-10-31  发布在  Spring
关注(0)|答案(6)|浏览(155)

我正在尝试用Google添加oauth2,遵循these instructions
启动服务器时收到以下错误消息:

Exiting
You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).

This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.

Here's the backtrace:

/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `block in load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/spring-1.7.2/lib/spring/binstub.rb:11:in `<top (required)>'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:133:in `rescue in require'
/Users/omonia/.rbenv/versions/2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:40:in `require'
/Users/omonia/Dropbox/MyApp/bin/spring:13:in `<top (required)>'

已安装的相关gem:

gem 'google-api-client', '0.9'
gem 'omniauth'
gem 'omniauth-google_oauth2'

将以下代码添加到config/initializers/omniauth.rb:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google_oauth2, 'my Google client id', 'my Google client secret', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end

这是怎么回事?按照错误说明操作不会改变任何东西(Spring是最新的1.7.2版本,运行bundle exec spring binstub --all只返回“spring already present”)。

iyr7buue

iyr7buue1#

把我的评论作为答案,因为OP确认它确实帮助了他。按照下面的步骤安装新的Spring并解决问题:

  • 运行此bin/spring binstub --remove --all
  • 请从Gemfile中删除gem并运行bundle install
  • 现在将gem "spring", group: :development添加到Gemfile中,按照文档运行bundle installbundle exec spring binstub --all。现在一切都应该正常了。
xienkqul

xienkqul2#

在代码升级到新的Rails版本后,我也遇到了类似的问题,下面的评论帮助我解决了这个问题:
https://github.com/rails/spring/issues/610#issuecomment-578188439
基本上,在bin/rails stub中禁用spring加载程序,然后运行rails s,直到发现并修复所有代码问题,最后,启用spring back。

6tqwzwtp

6tqwzwtp3#

检查config/initializers/omniauth.rb文件,确保您具有以下内容:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :google, 'Client_Id', 'Client_Secret'
end

确保你确实有谷歌的供应商(不是github或facebook)

41ik7eoe

41ik7eoe4#

这对我很有效-
我在控制台rake rails:update:bin上运行了这个
然后我运行了bundle exec spring binstub --all
我不能保证这对所有人都有效。
谢谢你:)

gopyfrb3

gopyfrb35#

首先,我不是Ruby On RailsMaven,所以如果我在下面的步骤中做错了什么,请纠正我。
对我有效的步骤如下,
从MacOS终端运行以下命令..
储物箱/Spring储物箱存根--移除--全部

**删除“供应商”下的“您的缓存”文件夹(使用Finder)

捆绑包安装。
Rails资源:预编译

hs1rzwqc

hs1rzwqc6#

在将我的ruby版本从2.6.1升级到2.7.1,将rails 5升级到rails 6之后,我也遇到了类似的问题。
我在这里阅读了讨论,并在禁用我的*加载Spring代码*之后,将其bin/rails


# !/usr/bin/env ruby

begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

收件人:


# !/usr/bin/env ruby

APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

我得到了错误
/home/humayun/.rbenv/版本/2.7.1/lib/ruby/gems/2.7.0/gems/引导快照-1.7.3/lib/引导快照/加载路径缓存/内核扩展/内核需要.rb:23:在需要':无法加载此类文件-- thwait(LoadError)
我通过在gem文件中添加以下gem来解决这个问题。

gem 'cmath'
gem 'scanf'
gem 'shell'
gem 'sync'
gem 'thwait'
gem 'e2mmap'

在这之后,我的rails s运行良好,我将bin/rails移到它的原始代码中。

相关问题