如何在 Rails 3 中将 OmniAuth 与 Memcache 存储结合使用?

发布于 2024-11-09 10:56:18 字数 470 浏览 0 评论 0原文

我想将 Memcache 用于 OmniAuth 商店,但我找不到任何有关如何执行此操作的示例。文件系统 tmp 不适用于我的主机。如何将下面的omniauth.rb 中的代码转换为使用Memcache。另外,我是否需要任何额外的 gem 才能让 Memcache 正常工作?

谢谢!!

当前的omniauth.rb:

require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do    
    provider :open_id, OpenID::Store::Filesystem.new('/tmp'), {:name => "google", :domain => "https://www.google.com/accounts/o8/id" }
end

I would like to use Memcache for OmniAuth's store but I cannot find any examples on how to do this. Filesystem tmp is not working for my host. How can I convert the code in my omniauth.rb below to use Memcache. Also do I need any extra gems to get Memcache to work?

Thanks!!

current omniauth.rb:

require 'openid/store/filesystem'
Rails.application.config.middleware.use OmniAuth::Builder do    
    provider :open_id, OpenID::Store::Filesystem.new('/tmp'), {:name => "google", :domain => "https://www.google.com/accounts/o8/id" }
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2024-11-16 10:56:18

我猜你在 Heroku,因为我也遇到了一些麻烦。我在 Heroku 上使用标准 Memcached 库时遇到了一些问题,尽管我现在不记得它们是什么了。我最终使用 Dalli 代替,它在那里工作得很好。

不幸的是,默认的 ruby​​-openid 无法与 Dalli 作为客户端一起使用,并且似乎不再积极维护。我有一个一个分支,它既可以解决这个问题,也可以在 Gemfile 中使用。

无论如何,以下内容应该适合您:

初始化程序:

require 'openid/store/memcache'

Rails.application.middleware.use OmniAuth::Builder do
  provider :open_id, OpenID::Store::Memcache.new(Dalli::Client.new), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end

Gemfile:

gem 'dalli', '1.0.2'
gem 'ruby-openid', :git => 'git://github.com/chanks/ruby-openid.git', :ref => '9ec3b76'

抱歉,我知道这很痛苦。如果您找到更好的解决方案,请告诉我!

I'm guessing you're on Heroku, since I went through some trouble with this too. I ran into some problems using the standard Memcached library on Heroku, though I don't recall what they were now. I wound up using Dalli instead, which works great there.

Unfortunately, the default ruby-openid doesn't work with Dalli as a client, and doesn't appear to be actively maintained any longer. I have a fork that both fixes that issue and can be used in a Gemfile too.

Anyway, the following should work for you:

Initializer:

require 'openid/store/memcache'

Rails.application.middleware.use OmniAuth::Builder do
  provider :open_id, OpenID::Store::Memcache.new(Dalli::Client.new), :name => 'google', :identifier => 'https://www.google.com/accounts/o8/id'
end

Gemfile:

gem 'dalli', '1.0.2'
gem 'ruby-openid', :git => 'git://github.com/chanks/ruby-openid.git', :ref => '9ec3b76'

Sorry, I know that this is a pain. If you find a better solution, please let me know!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文