pencil_automator/auth-test.php

123 lines
4 KiB
PHP

<?php
/**
* Authentication Test Page
* Shows current authentication status and configuration
*/
require_once __DIR__ . '/AuthMiddleware.php';
$auth = new AuthMiddleware();
$authStatus = $auth->isAuthenticated();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Auth Test - PencilAutomator</title>
<style>
body {
font-family: 'Courier New', monospace;
background: #1e1e1e;
color: #0f0;
padding: 40px;
max-width: 800px;
margin: 0 auto;
}
h1 {
color: #18A0FB;
border-bottom: 2px solid #18A0FB;
padding-bottom: 10px;
}
.section {
background: #2c2c2c;
padding: 20px;
margin: 20px 0;
border-radius: 8px;
border: 1px solid #444;
}
.label {
color: #ff0;
font-weight: bold;
}
.value {
color: #0ff;
}
.success {
color: #0f0;
}
.error {
color: #f00;
}
pre {
background: #000;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
}
</style>
</head>
<body>
<h1>🔐 Authentication Test Page</h1>
<div class="section">
<h2>SSO Configuration</h2>
<p><span class="label">SSO Enabled:</span> <span class="value"><?php echo SSO_ENABLED ? 'YES' : 'NO'; ?></span></p>
<p><span class="label">Tenant ID:</span> <span class="value"><?php echo SSO_TENANT_ID ?: '(not set)'; ?></span></p>
<p><span class="label">Client ID:</span> <span class="value"><?php echo SSO_CLIENT_ID ?: '(not set)'; ?></span></p>
</div>
<div class="section">
<h2>Authentication Status</h2>
<p><span class="label">Authenticated:</span>
<span class="<?php echo $authStatus['authenticated'] ? 'success' : 'error'; ?>">
<?php echo $authStatus['authenticated'] ? 'YES ✓' : 'NO ✗'; ?>
</span>
</p>
<?php if ($authStatus['authenticated']): ?>
<p><span class="label">User Name:</span> <span class="value"><?php echo htmlspecialchars($authStatus['user']['name'] ?? 'Unknown'); ?></span></p>
<p><span class="label">Email:</span> <span class="value"><?php echo htmlspecialchars($authStatus['user']['preferred_username'] ?? $authStatus['user']['upn'] ?? 'Unknown'); ?></span></p>
<?php else: ?>
<p><span class="label">Error:</span> <span class="error"><?php echo htmlspecialchars($authStatus['error'] ?? 'Not authenticated'); ?></span></p>
<?php endif; ?>
</div>
<div class="section">
<h2>Cookie Information</h2>
<p><span class="label">Auth Token Cookie:</span>
<span class="<?php echo isset($_COOKIE['auth_token']) ? 'success' : 'error'; ?>">
<?php echo isset($_COOKIE['auth_token']) ? 'Present ✓' : 'Not Found ✗'; ?>
</span>
</p>
</div>
<?php if ($authStatus['authenticated'] && isset($authStatus['user'])): ?>
<div class="section">
<h2>User Payload (Debug)</h2>
<pre><?php echo htmlspecialchars(json_encode($authStatus['user'], JSON_PRETTY_PRINT)); ?></pre>
</div>
<?php endif; ?>
<div class="section">
<h2>Actions</h2>
<p><a href="index.php" style="color: #18A0FB;">← Back to Application</a></p>
<?php if ($authStatus['authenticated'] && SSO_ENABLED): ?>
<p><a href="#" onclick="logout()" style="color: #f00;">Logout</a></p>
<?php endif; ?>
</div>
<script>
function logout() {
fetch('auth.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'logout' })
})
.then(() => {
window.location.reload();
});
}
</script>
</body>
</html>