<commit_before>require 'rack'
require 'json'
require 'oh_auth/user'

module OhAuth
  module Endpoints
    class AuthenticateUser

      def self.call(env)
        request = Rack::Request.new(env)
        user    = User.find(request.params['username'])

        if user && user.authenticate?(request.params['password'])
          Rack::Response.new(success)
        else
          Rack::Response.new(error, 401)
        end
      end

      private

      def self.success
        JSON({
          "access_token"      => "<KEY>",
          "token_type"        => "example",
          "expires_in"        => 3600,
          "refresh_token"     => "<KEY>",
        })
      end

      def self.error
        JSON({ "error" => "invalid username or password" })
      end

    end
  end
end<commit_msg>Add the correct content type header<commit_after>require 'rack'
require 'json'
require 'oh_auth/user'

module OhAuth
  module Endpoints
    class AuthenticateUser

      def self.call(env)
        request = Rack::Request.new(env)
        user    = User.find(request.params['username'])

        if user && user.authenticate?(request.params['password'])
          render_json(success, 200)
        else
          render_json(error, 401)
        end
      end

      private

      def self.render_json(body, status_code)
        Rack::Response.new(body, status_code, {
          'Content-Type' => 'application/json'
        })
      end

      def self.success
        JSON({
          "access_token"      => "<KEY>",
          "token_type"        => "example",
          "expires_in"        => 3600,
          "refresh_token"     => "<KEY>",
        })
      end

      def self.error
        JSON({ "error" => "invalid username or password" })
      end

    end
  end
end

{'fraction_non_alphanumeric': 0.11744776962168267, 'fraction_numerical': 0.009599096555618294, 'mean_word_length': 1.8306709265175718, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2128340', 'n_tokens_mistral': 543, 'n_tokens_neox': 512, 'n_words': 117}