Problem

The "Salesforce auth token request version" setting in the setting form has the following definition:

// src/Form/MarketingCloudSettings.php

    $form['request_token_version'] = [
      '#type' => 'select',
      '#title' => $this->t('Salesforce auth token request version'),
      '#description' => $this->t('The newer version of token request requires different parameters to the legacy v1.'),
      '#options' => [
        'v1',
        'v2',
      ],
      '#default_value' => $config->get('request_token_version'),
    ];

Where the options have keys "0" for "v1" and "1" for "v2"

But the module checks for "v1" and "v2" keys during the Token request:

private function requestToken($clientId, $clientSecret) {
    try {
      \Drupal::logger(__METHOD__)->info('%message', ['%message' => 'Fetching a new token.']);
      $url = $this->config
        ->get('request_token_url');
      $requestVersion = $this->config
        ->get('request_token_version');

      switch ($requestVersion) {
        case 'v1':
          $url .= '/v1/requestToken';
          $formParams = [
            'clientId' => $clientId,
            'clientSecret' => $clientSecret,
          ];
          $accessToken = 'accessToken';
          break;

        case 'v2':
        default:
          $url .= '/v2/token';
          $formParams = [
            'client_id' => $clientId,
            'client_secret' => $clientSecret,
            'grant_type' => 'client_credentials',
          ];
          $accessToken = 'access_token';
          break;
      }

So in the result default case ("v2") is always using.

Proposed resolution

Replace values "0" and "1" by values "v1" and "v2" on the settings form and update existing configs.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Oleksiy created an issue. See original summary.

Oleksiy’s picture

Assigned: Oleksiy » Unassigned
Status: Active » Needs review
FileSize
1.37 KB
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to go

  • Oleksiy authored 963e4c6 on 8.x-1.x
    Issue #3164764 by Oleksiy, andypost: The module is always using v2...
john_a’s picture

Many thanks for taking the time to create and test this patch.

This patch has been applied to 8.x-1.x and 8.x-1.x-dev and will be included in the next release.

john_a’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.