Files
2026-03-30 17:39:13 +09:00

118 lines
3.9 KiB
HTML

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MCPletA2A — Passkey 認証</title>
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'">
<style>
*, *::before, *::after { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
margin: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
background: #f0f2f5;
color: #333;
}
.card {
background: #fff;
border-radius: 12px;
box-shadow: 0 4px 24px rgba(0,0,0,0.1);
padding: 40px 48px;
max-width: 400px;
width: 90%;
text-align: center;
}
.icon { font-size: 48px; margin-bottom: 16px; }
h1 { font-size: 20px; margin: 0 0 12px; }
.prompt { color: #555; font-size: 15px; line-height: 1.5; margin-bottom: 28px; }
.btn {
display: block;
width: 100%;
padding: 14px;
border: none;
border-radius: 8px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: opacity 0.2s;
}
.btn:hover { opacity: 0.88; }
.btn-primary { background: #1a73e8; color: #fff; margin-bottom: 12px; }
.btn-cancel { background: #f1f3f4; color: #555; font-weight: 400; }
.status { margin-top: 16px; font-size: 14px; color: #888; min-height: 20px; }
.success-msg { color: #1e8e3e; font-weight: 600; }
</style>
</head>
<body>
<div class="card">
<div class="icon">🔐</div>
<h1>Passkey 認証</h1>
<p class="prompt" id="promptMsg">{{PROMPT_MESSAGE}}</p>
<button class="btn btn-primary" id="authBtn">Passkey で認証する</button>
<button class="btn btn-cancel" id="cancelBtn">キャンセル</button>
<p class="status" id="status"></p>
</div>
<script>
const PORT = {{PORT}};
const baseUrl = 'http://127.0.0.1:' + PORT;
const statusEl = document.getElementById('status');
function setStatus(msg, isSuccess) {
statusEl.textContent = msg;
statusEl.className = 'status' + (isSuccess ? ' success-msg' : '');
}
document.getElementById('authBtn').addEventListener('click', async () => {
document.getElementById('authBtn').disabled = true;
setStatus('認証中...');
try {
// Production: call navigator.credentials.get() with challenge from FIDO2 server.
// Demo: simulate a successful WebAuthn assertion.
const mockAssertion = {
type: 'passkey_assertion',
challenge: 'demo-challenge-' + Date.now(),
clientDataJSON: btoa(JSON.stringify({ type: 'webauthn.get', challenge: 'demo', origin: baseUrl })),
authenticatorData: btoa('demo-authenticator-data'),
signature: btoa('demo-signature-' + Math.random().toString(36).slice(2)),
userHandle: btoa('demo-user')
};
const res = await fetch(baseUrl + '/passkey/callback', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(mockAssertion)
});
if (res.ok) {
setStatus('認証完了!このウィンドウを閉じてください。', true);
setTimeout(() => window.close(), 1500);
} else {
setStatus('認証に失敗しました。再試行してください。');
document.getElementById('authBtn').disabled = false;
}
} catch (e) {
setStatus('エラー: ' + e.message);
document.getElementById('authBtn').disabled = false;
}
});
document.getElementById('cancelBtn').addEventListener('click', async () => {
try {
await fetch(baseUrl + '/passkey/cancel', { method: 'POST' });
} finally {
window.close();
}
});
</script>
</body>
</html>