You are here

public function SalesforceAuthProviderPluginBase::save in Salesforce Suite 8.3

Same name and namespace in other branches
  1. 8.4 src/SalesforceAuthProviderPluginBase.php \Drupal\salesforce\SalesforceAuthProviderPluginBase::save()
  2. 5.0.x src/SalesforceAuthProviderPluginBase.php \Drupal\salesforce\SalesforceAuthProviderPluginBase::save()

Callback for configuration form after saving config entity.

Parameters

array $form: The configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Overrides SalesforceAuthProviderInterface::save

File

src/SalesforceAuthProviderPluginBase.php, line 194

Class

SalesforceAuthProviderPluginBase
Shared methods for auth providers.

Namespace

Drupal\salesforce

Code

public function save(array $form, FormStateInterface $form_state) {

  // Initialize identity if token is available.
  if (!$this
    ->hasAccessToken()) {
    return TRUE;
  }
  $token = $this
    ->getAccessToken();
  $headers = [
    'Authorization' => 'OAuth ' . $token
      ->getAccessToken(),
    'Content-type' => 'application/json',
  ];
  $data = $token
    ->getExtraParams();
  $response = $this->httpClient
    ->retrieveResponse(new Uri($data['id']), [], $headers);
  $identity = $this
    ->parseIdentityResponse($response);
  $this->storage
    ->storeIdentity($this
    ->service(), $identity);
  return TRUE;
}