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.4.4 app/services/bookends/glostick_user_extractor.rb
bookends-10.4.3 app/services/bookends/glostick_user_extractor.rb
bookends-10.4.2 app/services/bookends/glostick_user_extractor.rb
bookends-10.4.1 app/services/bookends/glostick_user_extractor.rb
bookends-10.4.0 app/services/bookends/glostick_user_extractor.rb
bookends-10.3.4 app/services/bookends/glostick_user_extractor.rb
bookends-10.3.3 app/services/bookends/glostick_user_extractor.rb
bookends-10.3.2 app/services/bookends/glostick_user_extractor.rb
bookends-10.3.1 app/services/bookends/glostick_user_extractor.rb
bookends-10.3.0 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.8 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.7 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.6 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha8 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha7 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha6 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha5 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha4 app/services/bookends/glostick_user_extractor.rb
bookends-10.2.5.alpha3 app/services/bookends/glostick_user_extractor.rb