How do I use OmniAuth with a Memcache store in Rails 3?
I wou开发者_开发技巧ld 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
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!
精彩评论