Let me start by thank you for taking the time. I'm a newbie so let me know if you need more information.
So I'm trying to setup an OAUTH2 client in Laravel to connect up to an API provided by CLIO. I'm using PHPLeague's OAuth2 Client Library which uses GUZZLE to handle HTTP.
I was able to setup the client to redirect to Clio's Authorization page, authorize the access, get redirected to my app and receive an authorization code.
In the next step where I need to send a request to get an Access Token something goes wrong!
Here is the error I receive:
Type error: Argument 1 passed to League\OAuth2\Client\Provider\AbstractProvider::prepareAccessTokenResponse() must be of the type array, string given, called in /Users/patrick/Sites/ssacorp/vendor/league/oauth2-client/src/Provider/AbstractProvider.php on line 565
Now, in order to track it down, I know the following method is called to start fetching the access token:
public function getAccessToken($grant, array $options = [])
{
$grant = $this->verifyGrant($grant);
$params = [
'client_id' => $this->clientId,
'client_secret' => $this->clientSecret,
'redirect_uri' => $this->redirectUri,
];
$params = $grant->prepareRequestParameters($params, $options);
$request = $this->getAccessTokenRequest($params);
$response = $this->getParsedResponse($request);
$prepared = $this->prepareAccessTokenResponse($response);
$token = $this->createAccessToken($prepared, $grant);
return $token;
}
I dumped the properties and I get:
$params
array(5) { ["client_id"]=> string(40) "*************************************" ["client_secret"]=> string(40) "************************************" ["redirect_uri"]=> string(26) "http://app.ssadv.org/oauth" ["grant_type"]=> string(18) "authorization_code" ["code"]=> string(20) "******************" }
So everything seems normal here. I'm not sharing these credentials of course.
$request
object(GuzzleHttp\Psr7\Request)#179 (7) { ["method":"GuzzleHttp\Psr7\Request":private]=> string(4) "POST" ["requestTarget":"GuzzleHttp\Psr7\Request":private]=> NULL ["uri":"GuzzleHttp\Psr7\Request":private]=> object(GuzzleHttp\Psr7\Uri)#181 (7) { ["scheme":"GuzzleHttp\Psr7\Uri":private]=> string(4) "http" ["userInfo":"GuzzleHttp\Psr7\Uri":private]=> string(0) "" ["host":"GuzzleHttp\Psr7\Uri":private]=> string(12) "app.clio.com" ["port":"GuzzleHttp\Psr7\Uri":private]=> NULL ["path":"GuzzleHttp\Psr7\Uri":private]=> string(12) "/oauth/token" ["query":"GuzzleHttp\Psr7\Uri":private]=> string(0) "" ["fragment":"GuzzleHttp\Psr7\Uri":private]=> string(0) "" } ["headers":"GuzzleHttp\Psr7\Request":private]=> array(2) { ["Host"]=> array(1) { [0]=> string(12) "app.clio.com" } ["content-type"]=> array(1) { [0]=> string(33) "application/x-www-form-urlencoded" } } ["headerNames":"GuzzleHttp\Psr7\Request":private]=> array(2) { ["content-type"]=> string(12) "content-type" ["host"]=> string(4) "Host" } ["protocol":"GuzzleHttp\Psr7\Request":private]=> string(3) "1.1" ["stream":"GuzzleHttp\Psr7\Request":private]=> object(GuzzleHttp\Psr7\Stream)#183 (7) { ["stream":"GuzzleHttp\Psr7\Stream":private]=> resource(262) of type (stream) ["size":"GuzzleHttp\Psr7\Stream":private]=> NULL ["seekable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["readable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["writable":"GuzzleHttp\Psr7\Stream":private]=> bool(true) ["uri":"GuzzleHttp\Psr7\Stream":private]=> string(10) "php://temp" ["customMetadata":"GuzzleHttp\Psr7\Stream":private]=> array(0) { } } } inside Transfer
$response
This is actually the string going into the method prepareAccessTokenResponse() which is supposed to be an array and is causing the main error. Dumping it reveals that its actually a 404 HTML page by CLIO:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n
\n
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n
\n
<head>\n
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n
<title>The page you were looking for doesn't exist (404)</title>\n
</head>\n
\n
<body>\n
<!-- This file lives in public/404.html -->\n
\n
<div class="dialog">\n
<h1>The page you were looking for doesn't exist.</h1>\n
<p>You may have mistyped the address or the page may have moved.</p>\n
</div>\n
</body>\n
\n
</html>
I have tested the link and parameters in Postman and confirmed the access token is in fact returned using the same URI and information in my $params. Why am I getting a 404 when my URI is correct and $request says it is using POST method as it has to. To confirm this though, I tried using Chrome's Dev Tools Network tool but was unable to find a POST call to that link. How else should I troubleshoot this to make sure Guzzle is sending the right data to the right address?