revolut-php
revolut-php copied to clipboard
Incorrect Request
Hi, at first, thank you for your work !
I'm trying to use your code to connect my Revolut account. All's working fine on the first connect (i list my accounts successfully), but when i refresh my webpage, using the same code (code is persistant through GET), i can see an error 500 on my webpage, and in apache logs.
PHP Fatal error: Uncaught League\OAuth2\Client\Provider\Exception\IdentityProviderException: Incorrect request token in /var/www/erp/revolut/vendor/vdbelt/oauth2-revolut/src/Provider/Revolut.php:98\nStack trace:\n#0 /var/www/erp/revolut/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(628): League\OAuth2\Client\Provider\Revolut->checkResponse(Object(GuzzleHttp\Psr7\Response), Array)\n#1 /var/www/erp/revolut/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(537): League\OAuth2\Client\Provider\AbstractProvider->getParsedResponse(Object(GuzzleHttp\Psr7\Request))\n#2 /var/www/erp/revolut/vendor/vdbelt/oauth2-revolut/src/Provider/Revolut.php(144): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\AuthorizationCode), Array)\n#3 /var/www/erp/revolut/oauth.php(14): League\OAuth2\Client\Provider\Revolut->getAccessToken('authorization_c...', Array)\n#4 {main}\n thrown in /var/www/erp/revolut/vendor/vdbelt/oauth2-revolut/src/Provider/Revolut.php on line 98
So, when i authenticate, i am redirected to this php page, and i can get accounts. When i refresh this same webpage ($_GET["code"] is still here), i get this error.
Any help ? Thanks !
require "vendor/autoload.php";
$authProvider = new \RevolutPHP\Auth\Provider([ 'clientId' => 'myclientid', // As shown when uploading your key 'privateKey' => 'myprivatekey, 'redirectUri' => 'myredirecturi(to this webpage)', // The URL to redirect the user to after the authorisation step 'isSandbox' => false ]);
if($_GET["code"]=='') { $url = $authProvider->getAuthorizationUrl(); header("location:".$url); }
$accessToken = $authProvider->getAccessToken('authorization_code', ['code' => $_GET['code']]);
use RevolutPHP\Client;
$client = new Client($accessToken); $accounts = $client->accounts->all();
print_r($accounts);
I figured out man,
you should build the software by yourself, it's not difficult
The authorization code you get back from Revolut through the GET parameter is only valid once.
$accessToken = $authProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
You'll need to save the accessToken (eg in a session) and reuse it for as long as it is valid.
See https://github.com/sverraest/revolut-php#quick-start