Sha256: ad76d268b24378016f66c9c46cff4edea7bbac78bfbad575648fedbb4eb6cac8

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

require 'warden'
require 'warden/cookie_session/version'
require 'warden/cookie_session/default_wrapper'
require 'warden/cookie_session/configuration'
require 'warden/cookie_session/strategy'

module Warden
  module CookieSession

    class << self

      attr_accessor :config

    end

    self.config ||= Warden::CookieSession::Configuration.new

    class << self

      def configure
        self.config ||= Warden::CookieSession::Configuration.new
        yield(config)
        setup_warden(config)
      end

      def setup_warden(config)
        Warden::Strategies.add(:cookie_session, Warden::CookieSession::Strategy)

        Warden::Manager.after_set_user do |user, auth, _opts|
          encrypted_cookie = Warden::CookieSession::Strategy.encrypted_cookie(auth.cookies)
          encrypted_cookie.put(config.serialize_record(user), domain: auth.request.domain)
        end

        Warden::Manager.before_logout do |_user, auth, _opts|
          encrypted_cookie = Warden::CookieSession::Strategy.encrypted_cookie(auth.cookies)
          encrypted_cookie.clear
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
warden_cookie_session-0.1.1.18842 lib/warden/cookie_session.rb
warden_cookie_session-0.1.0.18828 lib/warden/cookie_session.rb
warden_cookie_session-0.1.0.18794 lib/warden/cookie_session.rb