Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

warden_cookie_session

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

warden_cookie_session

  • 0.1.2.19275
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Gem Version Gem YARD

Coverage Quality Outdated Vulnerabilities

Warden Cookie Session is a warden strategy to store auth in custom encrypted cookie(instead of rack:session). The main puprpose to allow store authorization between multiple rails applications, without sharing secret_key_base.

Usage

Setup Warden::CookieSession in initializer and provide wrapper.


Warden::CookieSession.configure do |config|
  config.cookie = Rails.application.secrets['shared_cookie']
  config.secret = Rails.application.secrets['shared_secret']

  config.wrapper = Warden::CookieSession::DefaultWrapper.new(User)
end

Default wrapper just fetch user from model:

module Warden
  module CookieSession
    class DefaultWrapper

      def initialize(klass = nil)
        @klass = klass
      end

      def serialize_record(record)
        # like in https://github.com/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb
        [record.to_key, record.authenticatable_salt]
      end

      def fetch_record(key)
        @klass.find(key.first)
      end

      def validate_record(record, salt)
        # like in https://github.com/plataformatec/devise/blob/master/lib/devise/models/authenticatable.rb
        record if record && record.authenticatable_salt == salt
      end

    end
  end
end

Advansed Usage

With Warden::CookieSession we can fetch user data remotly ex. from API:


Warden::CookieSession.configure do |config|
  config.cookie = Rails.application.secrets['shared_cookie']
  config.secret = Rails.application.secrets['shared_secret']

    class RemoteWrapper
      def serialize_record(record)
        [record.to_key, record.authenticatable_salt]
      end

      def fetch_record(key)
        FetchRemoteUserAndSalt.run!(key)
      end

      def validate_record(record, salt)
        record if record && record.authenticatable_salt == salt
      end

    end

  config.wrapper = Warden::CookieSession::DefaultWrapper.new(User)
end

Installation

It's a gem:

  gem install warden_cookie_session

There's also the wonders of the Gemfile:

  gem 'warden_cookie_session'

FAQs

Package last updated on 15 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc