Files
TechOdyssey_Designs_Dashboard/assets/php/etsyData/callbackEtsy.php
2025-01-04 14:27:31 +00:00

34 lines
1007 B
PHP

<?php
include '/mnt/www-live/TechOdyssey_Designs_Dashboard/assets/php/session_check.php';
require '/mnt/www-live/TechOdyssey_Designs_Dashboard/assets/php/envLoader.php'; // Load envLoader from php/
loadEnv(__DIR__ . '/../../../.env'); // Go up three levels to find .env
session_start();
if ($_GET['state'] !== $_SESSION['oauth_state']) {
die('Invalid state. Possible CSRF attack.');
}
$code = $_GET['code'];
$clientId = $_ENV['ETSY_KEYSTRING'];
$clientSecret = $_ENV['ETSY_SECRET'];
$redirectUri = $_ENV['ETSY_REDIRECT_URI'];
$data = [
'grant_type' => 'authorization_code',
'client_id' => $clientId,
'client_secret' => $clientSecret,
'code' => $code,
'redirect_uri' => $redirectUri
];
$ch = curl_init("https://api.etsy.com/v3/public/oauth/token");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
$tokens = json_decode($response, true);
file_put