Add Google OAuth admin login; fix header comment; both auth methods active

This commit is contained in:
2026-05-29 15:13:38 +00:00
parent 53f9f3e4da
commit e344e52d70
4 changed files with 167 additions and 3 deletions
+30
View File
@@ -0,0 +1,30 @@
<?php
/**
* Redirect to Google OAuth — admin login entry point
*/
require_once __DIR__ . '/../../../includes/auth.php';
if (AdminAuth::isLoggedIn()) {
header('Location: /admin/');
exit;
}
if (!defined('GOOGLE_CLIENT_ID') || !GOOGLE_CLIENT_ID) {
die('Google OAuth is not configured. Set GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET in config.');
}
$state = bin2hex(random_bytes(16));
$_SESSION['google_oauth_state'] = $state;
$params = http_build_query([
'client_id' => GOOGLE_CLIENT_ID,
'redirect_uri' => GOOGLE_REDIRECT_URI,
'response_type' => 'code',
'scope' => 'openid email profile',
'state' => $state,
'access_type' => 'online',
'prompt' => 'select_account',
]);
header('Location: https://accounts.google.com/o/oauth2/v2/auth?' . $params);
exit;