exact-php-client
exact-php-client copied to clipboard
Error 400: Signed data extraction has failed when try to get access token using authorization code
I have used below function for authorization:
public function authorize()
{
$connection = new Connection();
$connection->setRedirectUrl(env("EXACT_CALLBACK_URL"));
$connection->setExactClientId(env("EXACT_CLIENT_ID"));
$connection->setExactClientSecret(env("EXACT_CLIENT_SECRET"));
$connection->redirectForAuthorization();
}
After getting authorization code below function used to get code:
if (isset($_GET['code']) && is_null(getValue('authorizationcode'))) {
setValue('authorizationcode', $_GET['code']);
$request->session()->put('authorizationcode',$_GET['code']);
}
// If we do not have a authorization code, authorize first to setup tokens
if (!$request->session()->has('authorizationcode')) {
$exact = new \App\Http\Controllers\ExactOnlineController();
$exact->authorize();
}
Then I have used below connect function to get access token using authorization code:
public function connect($request)
{
$connection = new \Picqer\Financials\Exact\Connection();
$connection->setRedirectUrl(env("EXACT_CALLBACK_URL"));
$connection->setExactClientId(env("EXACT_CLIENT_ID"));
$connection->setExactClientSecret(env("EXACT_CLIENT_SECRET"));
// Retrieves authorizationcode from database
if ($request->session()->has('authorizationcode')) {
$connection->setAuthorizationCode($request->session()->get('authorizationcode'));
}
// Retrieves accesstoken from database
if (getValue('accesstoken')) {
$connection->setAccessToken(getValue('accesstoken'));
}
// Retrieves refreshtoken from database
if (getValue('refreshtoken')) {
$connection->setRefreshToken(getValue('refreshtoken'));
}
// Retrieves expires timestamp from database
if (getValue('expires_in')) {
$connection->setTokenExpires(getValue('expires_in'));
}
// Set callback to save newly generated tokens
$connection->setTokenUpdateCallback('tokenUpdateCallback');
// Make the client connect and exxchange tokens
try {
$connection->connect();
} catch (\Exception $e) {
throw new Exception('Could not connect to Exact: ' . $e->getMessage());
}
return $connection;
}
It's return below error: Invalid_request and message as 'Signed data extraction has failed'.
I'm not able to do first time connection. I have created one testing app on app center and using it's client_id, client_secret and redirect_uri. (I haven't published this test app yet just trying to connect with it.)
I have tried same API call in postman also and getting same error.
Let me know if I missed any configuration for app or mistake in connect function.
I noticed you are sending the request to exactonline.com
while the code
seems to be generated through exactonline.nl
. Are you sure you are not mixing up things?