<commit_before>module Doorkeeper::OAuth
  class AccountAccessTokenRequest
    include Doorkeeper::Validations
    include Doorkeeper::OAuth::Helpers

    validate :client,         :error => :invalid_client
    validate :original_resource_owner, :error => :invalid_original_resource_owner

    attr_accessor :server, :original_resource_owner, :client

    def initialize(server, client, original_resource_owner)
      @server          = server
      @original_resource_owner  = original_resource_owner
      @client          = client
    end

    def authorize
      validate
      @response = if valid?
        find_or_create_access_token
        TokenResponse.new access_token
      else
        ErrorResponse.from_request self
      end
    end

    def valid?
      self.error.nil?
    end

    def access_token
      return unless client.present? && original_resource_owner.present?
      @access_token ||= Doorkeeper::AccessToken.matching_token_for client, original_resource_owner.id, nil
    end

  private

    def find_or_create_access_token
      if access_token
        access_token.expired? ? revoke_and_create_access_token : access_token
      else
        create_access_token
      end
    end

    def revoke_and_create_access_token
      access_token.revoke
      create_access_token
    end

    def create_access_token
      @access_token = Doorkeeper::AccessToken.create!({
        :application_id     => client.id,
        :resource_owner_id  => original_resource_owner.id,
        :scopes             => '',<commit_msg>simpify account application authorize application<commit_after>module Doorkeeper::OAuth
  class AccountAccessTokenRequest
    include Doorkeeper::Validations
    include Doorkeeper::OAuth::Helpers

    validate :client,         :error => :invalid_client
    validate :original_resource_owner, :error => :invalid_original_resource_owner

    attr_accessor :server, :original_resource_owner, :client

    def initialize(server, client, original_resource_owner)
      @server          = server
      @original_resource_owner  = original_resource_owner
      @client          = client
    end

    def authorize
      validate
      @response = if valid?
        TokenResponse.new create_access_token
      else
        ErrorResponse.from_request self
      end
    end

    def valid?
      self.error.nil?
    end

  private

    def create_access_token
      @access_token = Doorkeeper::AccessToken.create!({
        :application_id     => client.id,
        :resource_owner_id  => original_resource_owner.id,
        :scopes             => '',
{'fraction_non_alphanumeric': 0.06312935708752905, 'fraction_numerical': 0.0, 'mean_word_length': 2.79295154185022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1211701', 'n_tokens_mistral': 710, 'n_tokens_neox': 690, 'n_words': 149}