31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Fetch Google Client ID from settings
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT setting_value FROM settings WHERE setting_key = 'google_client_id'");
|
|
$google_client_id = $stmt->fetchColumn();
|
|
} catch (PDOException $e) {
|
|
die('Database error fetching Google Client ID. Please configure it in the settings.');
|
|
}
|
|
|
|
if (empty($google_client_id)) {
|
|
die('Google Client ID is not configured. Please ask an administrator to set it up.');
|
|
}
|
|
|
|
$redirect_uri = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/google-callback.php';
|
|
|
|
$auth_url = 'https://accounts.google.com/o/oauth2/v2/auth?' . http_build_query([
|
|
'client_id' => $google_client_id,
|
|
'redirect_uri' => $redirect_uri,
|
|
'response_type' => 'code',
|
|
'scope' => 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
|
|
'access_type' => 'offline',
|
|
'prompt' => 'select_account'
|
|
]);
|
|
|
|
header('Location: ' . $auth_url);
|
|
exit;
|