philippurbschat.de/dinos/auth.php

65 lines
No EOL
2.3 KiB
PHP

<?php
/*
* 2026-01-08 16:05:00
* AUTHENTIFIZIERUNG PAGE
* Führt den Google Login durch und speichert den Token.
*/
require_once 'google_helper.php';
// Konfiguration
$secretFile = 'client_secret.json';
// WICHTIG: Hier muss exakt die URL stehen, die du in der Google Console eingetragen hast:
$redirectUri = 'https://philippurbschat.de/dinos/auth.php';
$google = new GoogleHelper($secretFile, $redirectUri);
// Szenario 1: Google schickt uns zurück (mit ?code=...)
if (isset($_GET['code'])) {
$success = $google->authenticate($_GET['code']);
if ($success) {
echo '<h1 style="color:green">Verbindung erfolgreich!</h1>';
echo '<p>Der Token wurde gespeichert (tokens.json). Du kannst dieses Fenster schließen.</p>';
echo '<a href="index.php">Zurück zum Dino-Generator</a>';
} else {
echo '<h1 style="color:red">Fehler beim Login</h1>';
echo '<p>Konnte Code nicht gegen Token tauschen.</p>';
}
exit;
}
// Szenario 2: Fehler von Google
if (isset($_GET['error'])) {
die("Google Fehler: " . htmlspecialchars($_GET['error']));
}
// Szenario 3: Startseite - Button anzeigen
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>Google Photos Verbindung</title>
<style>
body { font-family: sans-serif; background: #0f172a; color: white; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.card { background: #1e293b; padding: 40px; border-radius: 20px; text-align: center; box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.btn { background: #4285F4; color: white; padding: 15px 30px; text-decoration: none; border-radius: 8px; font-weight: bold; display: inline-block; margin-top: 20px; }
.btn:hover { background: #3367D6; }
</style>
</head>
<body>
<div class="card">
<h1>Google Photos verbinden</h1>
<p>Erlaube der Dino-App, Bilder in dein Album zu laden.</p>
<?php if ($google->isAuthenticated()): ?>
<p style="color: #4ade80;">✅ Bereits verbunden!</p>
<p style="font-size: 0.8em; opacity: 0.7;">(Erneuter Klick erneuert die Verbindung)</p>
<?php endif; ?>
<a href="<?php echo $google->getAuthUrl(); ?>" class="btn">
Mit Google anmelden
</a>
</div>
</body>
</html>