Good evening.
I need to find the “Codice Fiscale” field of the users that bought my object, to be able to issue my invoices.
I’m not able to get the Oauth Token. Searching the internet I found this library (pretty old!) https://github.com/neilcrookes/oauth2-ebay/tree/master. First of all I had some problem installing it with composer, because of some issues related to the non-stable version, so I installed manually.
This is the code I put together, from different sources.
session_start();
require 'vendor/autoload.php';
use LeagueOAuth2ClientProviderExceptionIdentityProviderException;
use NeilCrookesOAuth2ClientProviderEbay;
// Settings
$clientId = 'My_ID';
$clientSecret = 'My_Secret';
$redirectUri = 'My_URI';
// Crete the provider
$provider = new Ebay([
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'redirectUri' => $redirectUri,
'sandbox' => true,
]);
// if no authcode, redirect to eBay auth page
if (!isset($_GET['code'])) {
$authorizationUrl = $provider->getAuthorizationUrl();
$_SESSION['oauth2state'] = $provider->getState();
header('Location: ' . $authorizationUrl);
exit;
// Verify the state for CSRF validation
} elseif (empty($_GET['state']) || ($_GET['state'] !== $_SESSION['oauth2state'])) {
unset($_SESSION['oauth2state']);
exit('Invalid state');
} else {
try {
// Get the Token
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
// Show token data
echo '<h3>Access Token Details</h3>';
echo 'Access Token: ' . $accessToken->getToken() . "<br>";
echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
echo 'Expires: ' . date('Y-m-d H:i:s', $accessToken->getExpires()) . "<br>";
echo 'Has Expired: ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";
// Save token data to session
$_SESSION['accessToken'] = $accessToken->getToken();
$_SESSION['refreshToken'] = $accessToken->getRefreshToken();
$_SESSION['tokenExpires'] = $accessToken->getExpires();
} catch (IdentityProviderException $e) {
exit($e->getMessage());
}
}
When I first execute this, I have no auth code, so I’m redirected to the eBay auth page.
I login with my sandbox user and I get to the “OK page”. That’s it!
All the rest of the code is not executed (this does not surprise me) because I cannot get back to my original page to read the data.
What’s the good way to go on?
I really need that library?
Thanks