btg-sandbox-markdown-formatter/index.php
DJP 5e4d4d0115 Initial commit: Secure Markdown to HTML converter with Azure AD authentication
- Web-based Markdown formatter with real-time conversion
- Microsoft Azure AD authentication with PKCE flow
- Server-side JWT validation with httpOnly cookies
- Clipboard functionality for HTML/text output
- PHP backend with Composer dependency management
- Comprehensive README with installation instructions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-17 17:33:35 -04:00

93 lines
No EOL
3.2 KiB
PHP
Executable file

<?php
require_once 'config.php';
require_once 'AuthMiddleware.php';
// Require authentication for this page
$auth = new AuthMiddleware();
$user = $auth->requireAuth();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Markdown to HTML Converter</title>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<script src="https://alcdn.msauth.net/browser/2.15.0/js/msal-browser.min.js" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<div style="text-align: right; margin-bottom: 10px;">
<span style="margin-right: 10px;">Welcome, <?php echo htmlspecialchars($user['name'] ?? $user['preferred_username'] ?? 'User'); ?></span>
<button id="logout-button" onclick="signOut()">Log Out</button>
</div>
<div class="logo-container">
<img src="MD.svg" alt="MD Logo" class="logo">
</div>
<div class="converter">
<div class="input-area">
<h2>Markdown Input</h2>
<textarea id="markdown-input" placeholder="Enter your Markdown here..."></textarea>
</div>
<div class="output-area">
<h2>HTML Output</h2>
<div id="html-output"></div>
<div class="button-group">
<button id="select-all">Select All</button>
<button id="copy">Copy</button>
</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/2.0.3/marked.min.js"></script>
<script src="js/script.js"></script>
<script>
const msalConfig = {
auth: {
clientId: "01d33c7c-5640-4986-b4db-06af63a7d285",
authority: "https://login.microsoftonline.com/e519c2e6-bc6d-4fdf-8d9c-923c2f002385",
redirectUri: "https://brandtechsandbox.oliver.solutions/markdown-formatter/"
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true,
}
};
const myMSALObj = new msal.PublicClientApplication(msalConfig);
function signOut() {
// Call server to clear cookie
fetch('auth.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
action: 'logout'
})
})
.then(() => {
// Also clear MSAL session
myMSALObj.logoutPopup().then(() => {
window.location.reload();
}).catch(error => {
console.error("Logout error:", error);
window.location.reload(); // Reload anyway
});
})
.catch(error => {
console.error("Logout error:", error);
window.location.reload();
});
}
</script>
</body>
</html>