uzerpllp / uzerp

uzERP - Open Source Business Management
http://www.uzerp.com
Other
54 stars 24 forks source link

Handle HMRC MTD VAT API invalid_grant error #230

Closed steveblamey closed 3 years ago

steveblamey commented 3 years ago

When the Oauth grant expires and the token can no longer be refreshed, uzERP returns the content of the error message in the http response instead of redirecting to HMRC for the user to re-authorize the application.

MTD::refreshToken must start authorizationGrant when an invalid_grant error is received.

// If authorization grant has expired, re-authorise application
// >>> re-auth on invalid_grant
if ($response['error'] == 'invalid_request' || $response['error'] == 'invalid_grant') {
    $storage->deleteToken($this->config_key);
    $this->authorizationGrant();
}
$flash->addWarning("Oauth Error: {$response['error']}, {$response['error_description']}");
return false;