public static function getAccessToken(Client $client, $subdomain, array $params, $domain = 'zendesk.com')
{
$authUrl = "https://{$subdomain}.{$domain}/oauth/tokens";
// Fetch access_token
$params = array_merge(['code' => null, 'client_id' => null, 'client_secret' => null, 'grant_type' => 'authorization_code', 'scope' => 'read write', 'redirect_uri' => null], $params);
try {
$request = new Request('POST', $authUrl, ['Content-Type' => 'application/json']);
$request = $request->withBody(\GuzzleHttp\Psr7\stream_for(json_encode($params)));
$response = $client->send($request);
} catch (RequestException $e) {
throw new ApiResponseException($e);
}
return json_decode($response->getBody()->getContents());
}
public function testAccessTokenIsRequested() { $this->mockApiResponses([new Response(200, [], json_encode(['access_token' => 12345]))]); $params = ['code' => 'adwo123ijo', 'client_id' => 'test_client', 'client_secret' => 'dwapjoJ123d8w9a01-', 'grant_type' => 'authorization_code', 'scope' => 'read write', 'redirect_uri' => 'https://test.foo.com']; OAuth::getAccessToken($this->client->guzzle, 'test', $params); $this->assertLastRequestIs(['method' => 'POST', 'requestUri' => 'https://test.zendesk.com/oauth/tokens', 'postFields' => $params, 'headers' => ['accept' => false]]); }