You are here

public function RestClient::handleAuthResponse in Salesforce Suite 8.3

Helper callback for OAuth handshake, and refreshToken()

Parameters

\GuzzleHttp\Psr7\Response $response: Response object from refreshToken or authToken endpoints.

Overrides RestClientInterface::handleAuthResponse

Deprecated

in 8.x-4.0 and does not have an exact analog, refer to \OAuth\Common\Http\Client\StreamClient::retrieveResponse instead.

See also

SalesforceController::oauthCallback()

self::refreshToken()

1 call to RestClient::handleAuthResponse()
RestClient::refreshToken in src/Rest/RestClient.php
Refresh access token based on the refresh token.
1 method overrides RestClient::handleAuthResponse()
TestRestClient::handleAuthResponse in src/Tests/TestRestClient.php
Helper callback for OAuth handshake, and refreshToken()

File

src/Rest/RestClient.php, line 515

Class

RestClient
Objects, properties, and methods to communicate with the Salesforce REST API.

Namespace

Drupal\salesforce\Rest

Code

public function handleAuthResponse(Response $response) {
  if ($response
    ->getStatusCode() != 200) {
    throw new \Exception($response
      ->getReasonPhrase(), $response
      ->getStatusCode());
  }
  $data = (new RestResponse($response))->data;
  $this
    ->setAccessToken($data['access_token'])
    ->initializeIdentity($data['id'])
    ->setInstanceUrl($data['instance_url']);

  // Do not overwrite an existing refresh token with an empty value.
  if (!empty($data['refresh_token'])) {
    $this
      ->setRefreshToken($data['refresh_token']);
  }
  return $this;
}