/** * Fetch access token with a grant_type of client_credentials * * @access public * @return array * * throws \InvalidArgumentException * @throws HttpResponseException */ protected function getAccessToken() { $response = $this->httpClient->post(self::ENDPOINT_ACCESS_TOKEN, array('grant_type' => 'client_credentials', 'client_id' => self::$config['client_id'], 'client_secret' => self::$config['client_secret'], 'scope' => implode(',', self::$config['scopes']))); $data = json_decode($response->getContent(), true); if (json_last_error() !== JSON_ERROR_NONE) { $ex = new HttpResponseException('[access_token] Invalid JSON: ' . json_last_error_msg()); $ex->setResponse($this->httpClient->getLastResponse())->setRequest($this->httpClient->getLastRequest()); throw $ex; } if (false === array_key_exists('access_token', $data)) { throw new HttpResponseException('access_token is missing from response. ' . $response->getContent()); } return $data; }