Sha256: f10957b0b7002327c70e72ccf63cb9d924707bea571421991ec49c99bf487383

Contents?: true

Size: 777 Bytes

Versions: 60

Compression:

Stored size: 777 Bytes

Contents

module Bookends
  class GlostickUserExtractor
    attr_reader :secret,
                :token

    def initialize(cookies, secret)
      @secret = secret
      @token  = CGI::unescape(cookies[:heroku_user_session]) if cookies[:heroku_user_session]
    end

    def user
      session_info = decrypt_session_cookie
      if session_info && session_info['user']
        session_info['user']
      else
        {
          'email' => '',
          'full_name' => '',
          'id' => ''
        }
      end
    end

    private

    def decrypt_session_cookie
      return nil unless token && secret

      verifier = Fernet.verifier(secret, token)
      verifier.enforce_ttl = false

      return nil unless verifier.valid?

      JSON.parse(verifier.message)
    end
  end
end

Version data entries

60 entries across 60 versions & 1 rubygems

Version Path
bookends-10.2.5.alpha2 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha app/services/bookends/glostick_user_extractor.rb
bookends-10.2.4 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.3 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.1 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.0 app/services/bookends/glostick_user_extractor.rb
bookends-10.1.1 app/services/bookends/glostick_user_extractor.rb
bookends-10.1.0 app/services/bookends/glostick_user_extractor.rb
bookends-10.1.0beta2 app/services/bookends/glostick_user_extractor.rb
bookends-10.1.0beta1 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.6 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.5 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.4 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.3 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.2 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.1 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.0 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.0.rc5 app/services/bookends/glostick_user_extractor.rb
bookends-9.0.13 app/services/bookends/glostick_user_extractor.rb
bookends-10.0.0.rc4 app/services/bookends/glostick_user_extractor.rb