<?php
session_start();
require 'config.php'; // the config above

// Build URL to redirect user to Azure AD login
$auth_url = $authorize_url . '?' . http_build_query([
    'client_id' => $client_id,
    'response_type' => 'code',
    'redirect_uri' => $redirect_uri,
    'response_mode' => 'query',
    'scope' => $scope,
    'state' => bin2hex(random_bytes(8)),  // CSRF protection
]);

$_SESSION['oauth2state'] = $auth_url;

?>

<a href="<?php echo htmlspecialchars($auth_url); ?>">Login with Azure AD</a>
