<commit_before>module OmniAuth
  module Strategies
    class Cookie
      include OmniAuth::Strategy

      args [:endpoint, :callback_param]

      option :fields, [:id]

      uid do
        @id
      end

      info do
        {
        }
      end

      def request_phase
        redirect callback_url
      end

      def callback_phase
        token = request.cookies['token']

        if token.nil?
          uri = URI(api_uri)
          uri.query = URI.encode_www_form({ callback_param => callback_url }) unless callback_param.nil?
          redirect uri.to_s
        else
          id = CGI::unescape(token)
          @id = Base64.decode64(id)
          super
        end
      end

    protected

      def api_uri
        options.endpoint
      end

      def callback_param
        options.callback_param
      end

    end
  end
end<commit_msg>Handle new cookie based authentication<commit_after>module OmniAuth
  module Strategies
    class Cookie
      include OmniAuth::Strategy

      args [:endpoint, :callback_param]

      option :fields, [:id]

      uid do
        @id
      end

      info do
        {
        }
      end

      def request_phase
        redirect callback_url
      end

      def callback_phase
        # would be nice if you could pass a yield to this and handle it that way
        #options.func[self, request]

        lcghd = request.cookies['__lcghd']

        if lcghd.nil? # cookie doesn't exist, lets redirect to site to login
          uri = URI(api_uri)
          uri.query = URI.encode_www_form({ callback_param => callback_url }) unless callback_param.nil?
          redirect uri.to_s
        else
          json = %x(/bin/echo -n "#{lcghd}" | perl lib/decode.pl)
          if json.present?
            user = JSON.parse(json)
            @id = user['userid']
            super
          else
            # couldn't read cookie, something is up, redirect to the employee site.
            uri = URI(api_uri)
            uri.query = URI.encode_www_form({ callback_param => callback_url }) unless callback_param.nil?
            redirect uri.to_s
          end
        end
      end

    protected

      def api_uri
        options.endpoint
      end

      def callback_param
        options.callback_param
      end

    end
  end
end
{'fraction_non_alphanumeric': 0.06637554585152838, 'fraction_numerical': 0.0017467248908296944, 'mean_word_length': 1.6424452133794694, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7370526', 'n_tokens_mistral': 663, 'n_tokens_neox': 632, 'n_words': 185}