{"id":13508122,"url":"https://github.com/cconstantin/plug_rails_cookie_session_store","last_synced_at":"2025-04-05T22:10:34.047Z","repository":{"id":25181142,"uuid":"28604395","full_name":"cconstantin/plug_rails_cookie_session_store","owner":"cconstantin","description":"Rails compatible Plug session store","archived":false,"fork":false,"pushed_at":"2021-06-29T15:23:53.000Z","size":164,"stargazers_count":96,"open_issues_count":10,"forks_count":28,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T21:09:05.021Z","etag":null,"topics":["elixir-phoenix","elixir-plug","phoenix","plug","rails","ruby-on-rails"],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cconstantin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-29T19:56:49.000Z","updated_at":"2025-01-30T20:56:36.000Z","dependencies_parsed_at":"2022-08-23T18:00:48.780Z","dependency_job_id":null,"html_url":"https://github.com/cconstantin/plug_rails_cookie_session_store","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cconstantin%2Fplug_rails_cookie_session_store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cconstantin%2Fplug_rails_cookie_session_store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cconstantin%2Fplug_rails_cookie_session_store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cconstantin%2Fplug_rails_cookie_session_store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cconstantin","download_url":"https://codeload.github.com/cconstantin/plug_rails_cookie_session_store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406111,"owners_count":20933806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir-phoenix","elixir-plug","phoenix","plug","rails","ruby-on-rails"],"created_at":"2024-08-01T02:00:48.470Z","updated_at":"2025-04-05T22:10:34.022Z","avatar_url":"https://github.com/cconstantin.png","language":"Elixir","funding_links":[],"categories":["Framework Components","Elixir"],"sub_categories":[],"readme":"PlugRailsCookieSessionStore\n===========================\n\nRails compatible Plug session store.\n\nThis allows you to share session information between Rails and a Plug-based framework like Phoenix.\n\nVersion Information\n===================\n\nVersion 2.0 and higher require OTP 22 or higher.\n\n## Installation\n\nAdd PlugRailsCookieSessionStore as a dependency to your `mix.exs` file:\n\n```elixir\ndef deps do\n  [{:plug_rails_cookie_session_store, \"~\u003e 2.0\"}]\nend\n```\n\n## How to use with Phoenix\n\n#### Copy/share the encryption information from Rails to Phoenix.\n\nThere are 4 things to copy:\n* secret_key_base\n* signing_salt\n* encryption_salt\n* session_key\n\nSince Rails 5.2, `secret_key_base` in test and development is derived as a MD5 hash of the application's name. To fetch key value you can run:\n\n```\nRails.application.secret_key_base\n```\n\nhttps://www.rubydoc.info/github/rails/rails/Rails%2FApplication:secret_key_base\n\nThe `secret_key_base` should be copied to Phoenix's `config.exs` file. There should already be a key named like that and you should override it.\n\nThe other three values can be found somewhere in the initializers directory of your Rails project. Some people don't set the `signing_salt` and `encryption_salt`. If you don't find them, set them like so:\n\n```ruby\nRails.application.config.session_store :cookie_store, key: '_SOMETHING_HERE_session'\nRails.application.config.action_dispatch.encrypted_cookie_salt =  'encryption salt'\nRails.application.config.action_dispatch.encrypted_signed_cookie_salt = 'signing salt'\n```\n\n#### Configure the Cookie Store in Phoenix.\n\nEdit the `endpoint.ex` file and add the following:\n\n```elixir\n# ...\nplug Plug.Session,\n  store: PlugRailsCookieSessionStore,\n  key: \"_SOMETHING_HERE_session\",\n  domain: '.myapp.com',\n  secure: true,\n  signing_with_salt: true,\n  signing_salt: \"signing salt\",\n  encrypt: true,\n  encryption_salt: \"encryption salt\",\n  key_iterations: 1000,\n  key_length: 64,\n  key_digest: :sha,\n  serializer: Poison # see serializer details below\nend\n```\n\n#### Set up a serializer\n\nPlug \u0026 Rails must use the same strategy for serializing cookie data.\n\n- __JSON__: Since 4.1, Rails defaults to serializing cookie data with JSON. Support this strategy by getting a JSON serializer and passing it to `Plug.Session`. For example, add `Poison` to your dependencies, then:\n\n  ```elixir\n  plug Plug.Session,\n    store: PlugRailsCookieSessionStore,\n    # ... see encryption config above\n    serializer: Poison\n  end\n  ```\n\n  You can confirm that your app uses JSON by searching for\n\n  ```ruby\n  Rails.application.config.action_dispatch.cookies_serializer = :json\n  ```\n\n  in an initializer.\n\n- __Marshal__: Previous to 4.1, Rails defaulted to Ruby's [`Marshal` library](http://ruby-doc.org/core-2.3.0/Marshal.html) for serializing cookie data. You can deserialize this by adding [`ExMarshal`](https://hex.pm/packages/ex_marshal) to your project and defining a serializer module:\n\n  ```elixir\n  defmodule RailsMarshalSessionSerializer do\n    @moduledoc \"\"\"\n    Share a session with a Rails app using Ruby's Marshal format.\n    \"\"\"\n    def encode(value) do\n      {:ok, ExMarshal.encode(value)}\n    end\n\n    def decode(value) do\n      {:ok, ExMarshal.decode(value)}\n    end\n  end\n  ```\n\n  Then, pass that module as a serializer to `Plug.Session`:\n\n  ```elixir\n  plug Plug.Session,\n    store: PlugRailsCookieSessionStore,\n    # ... see encryption config above\n    serializer: RailsMarshalSessionSerializer\n  end\n  ```\n\n- __Rails 3.2__: Rails 3.2 uses unsalted signing, to make Phoenix share session with Rails 3.2 project you need to set up `ExMarshal` mentioned above, with following configuration in your `Plug.Session`:\n\n  ```elixir\n  plug Plug.Session,\n    store: PlugRailsCookieSessionStore,\n    # ... see encryption/ExMarshal config above\n    signing_with_salt: false,\n  end\n  ```\n\n\n#### That's it!\n\nTo test it, set a session value in your Rails application:\n\n```elixir\nsession[:foo] = 'bar'\n```\n\nAnd print it on Phoenix in whatever Controller you want:\n\n```elixir\nLogger.debug get_session(conn, \"foo\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcconstantin%2Fplug_rails_cookie_session_store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcconstantin%2Fplug_rails_cookie_session_store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcconstantin%2Fplug_rails_cookie_session_store/lists"}