📄 Source: oauth2callback.php
<?php
session_name('INBOXZERO');
session_start();
require_once 'vendor/autoload.php';
$baseUrl = "http://createcraftweb.playit.plus/AgentAIv3";
$client = new Google\Client();
$client->setClientId('1082083393389-c5uekspcp2boc1gd0n0gr3v1a5vbb3jg.apps.googleusercontent.com');
$client->setClientSecret('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');
$client->setRedirectUri("$baseUrl/oauth2callback.php");
$client->addScope('https://www.googleapis.com/auth/gmail.readonly');
$client->setAccessType('offline');
$client->setPrompt('consent');
if (isset($_GET['code'])) {
try {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
if (!isset($token['error'])) {
$_SESSION['access_token'] = $token;
if (!is_dir(__DIR__ . '/tmp')) {
mkdir(__DIR__ . '/tmp', 0755, true);
}
file_put_contents(__DIR__ . '/tmp/token.json', json_encode($token));
header('Location: index.php');
exit();
} else {
throw new Exception($token['error_description'] ?? 'Unknown error');
}
} catch (Exception $e) {
echo "Authentication failed: " . $e->getMessage();
echo "<br><a href='index.php'>Try again</a>";
}
} else {
echo "No authorization code received.";
echo "<br><a href='index.php'>Go back</a>";
}
?>
← Back