No commit activity in last 3 years
No release in over 3 years
Enable sessions/cookies in Rails that are compatible with standard rack apps
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0

Runtime

>= 1.6
 Project Readme

RailsRackSessionCookie

By default, Rails 4+ comes with its own custom cookie storage mechanism that encrypts cookie values. It is incompatible with Rack::Session::Cookie and only necessary if you're storing sensitive information in your cookies (an antipattern).

This gem allows you to seemlessly share a cookie among rack-based web applications, provided they all use the built-in Rack::Session middleware.

How does it work?

This simply replaces the ActionDispatch cookie middleware with Rack::Session::Storage. Unfortunately you cannot run ActionDispatch's cookie middleware alongside Rack::Session::Storage because ActionDispatch overwrites env['rack.session'] with its custom cookie jar.

By using this gem, all your rack and rails apps must use Rack::Session::Storage in order to share cookies.

Installation

Add this line to your application's Gemfile:

gem 'rails-rack-session'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-rack-session

Configuration

In config/application.rb:

config.rack_session = {
  store: :cookie,
  key: '_my_app',
  domain: '.example.com'
}

The :store key corresponds to the name of a Rack::Session class, e.g. Cookie. the :secret key is inferred from your app's secret_key_base, usually set in config/secrets.yml.

An optional :coder key can be given. By default, this is the Rack::Session::Cookie::Base64::JSON coder that serializes session data as JSON. This is more secure than Rack::Session's default marshalled hash.

Use the same keys used to configure Rack::Session. For cookie store, see http://www.rubydoc.info/gems/rack/Rack/Session/Cookie

Usage

This is a seamless drop-in as Rails' interface with the cookie store is compatible with Rack::Session::Cookie.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dkastner/rails-rack-session.