<commit_before>module Setup
  class LazadaAuthorization < Setup::Oauth2Authorization
    include CenitScoped
    include RailsAdmin::Models::Setup::LazadaAuthorizationAdmin

    build_in_data_type.with(:namespace, :name, :provider, :client, :parameters, :template_parameters, :scopes)
    build_in_data_type.referenced_by(:namespace, :name)

    auth_template_parameters access_token: ->(oauth2_auth) { oauth2_auth.fresh_access_token }

    def token_params(params = {}, template_parameters = {})
      super
      sign_params(params, template_parameters: {
        url: client.provider.token_endpoint,
        skip_access_token: true
      })
      params
    end

    def sign_params(params, template_parameters = {})
      params['app_key'] = client.get_identifier
      params['access_token'] = access_token unless template_parameters[:skip_access_token]
      params['sign_method'] = 'sha256'
      params['timestamp'] = (Time.now.utc.to_f * 1000).to_i
      path = URI.parse(
        template_parameters[:url].to_s.gsub(%r{\/+\Z}, '').strip +
          ('/' + template_parameters[:path].to_s).gsub(%r{\/+}, '/').strip
      ).path.to_s
      path.gsub!(/\A\/rest/, '')
      sign = (path + params.sort.flatten.join).hmac_hex_sha256(client.get_secret).upcase
      params['sign'] = sign
    end
  end
end<commit_msg>Authorization signing parameters (fixed, again)<commit_after>module Setup
  class LazadaAuthorization < Setup::Oauth2Authorization
    include CenitScoped
    include RailsAdmin::Models::Setup::LazadaAuthorizationAdmin

    build_in_data_type.with(:namespace, :name, :provider, :client, :parameters, :template_parameters, :scopes)
    build_in_data_type.referenced_by(:namespace, :name)

    auth_template_parameters access_token: ->(oauth2_auth) { oauth2_auth.fresh_access_token }

    def token_params(params = {}, template_parameters = {})
      super
      sign_params(params, url: client.provider.token_endpoint, skip_access_token: true)
      params
    end

    def sign_params(params, template_parameters = {})
      params['app_key'] = client.get_identifier
      params['access_token'] = access_token unless template_parameters[:skip_access_token]
      params['sign_method'] = 'sha256'
      params['timestamp'] = (Time.now.utc.to_f * 1000).to_i
      path = URI.parse(
        template_parameters[:url].to_s.gsub(%r{\/+\Z}, '').strip +
          ('/' + template_parameters[:path].to_s).gsub(%r{\/+}, '/').strip
      ).path.to_s
      path.gsub!(/\A\/rest/, '')
      sign = (path + params.sort.flatten.join).hmac_hex_sha256(client.get_secret).upcase
      params['sign'] = sign
    end
  end
end
{'fraction_non_alphanumeric': 0.13617344998098135, 'fraction_numerical': 0.0098896918980601, 'mean_word_length': 3.8345588235294117, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1997480', 'n_tokens_mistral': 847, 'n_tokens_neox': 826, 'n_words': 130}