261 lines
11 KiB
HTML
261 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>FIDO2 Device Manager Test</title>
|
|
<script src="files/popper.js"></script>
|
|
<script src="files/bootstrap.js"></script>
|
|
<script src="files/dfido2-lib.js"></script>
|
|
<script src="files/fido2-ui-sdk.js"></script>
|
|
<style>
|
|
body {
|
|
padding: 20px;
|
|
font-family: Arial, sans-serif;
|
|
}
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
}
|
|
#device-container {
|
|
margin-top: 20px;
|
|
}
|
|
.user-info {
|
|
background: #f5f5f5;
|
|
padding: 15px;
|
|
margin-bottom: 20px;
|
|
border-radius: 5px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>FIDO2 Device Manager Test</h1>
|
|
|
|
<div class="user-info">
|
|
<h3>User Information</h3>
|
|
<p><strong>User ID:</strong> <span id="current-user-id">test@example.com</span></p>
|
|
<p><strong>Status:</strong> Logged in (assumed)</p>
|
|
<p><small>Note: User ID will be displayed in the device manager UI when showUserInfo is enabled.</small></p>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="user-id-input">Enter User ID:</label>
|
|
<input type="text" id="user-id-input" class="form-control" value="test@example.com" style="max-width: 300px;">
|
|
</div>
|
|
|
|
<div class="form-group" style="margin-top: 15px;">
|
|
<label>Options:</label>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="show-user-info" checked>
|
|
<label class="form-check-label" for="show-user-info">
|
|
Show User Info (displays user ID in UI)
|
|
</label>
|
|
</div>
|
|
<div class="form-check">
|
|
<input class="form-check-input" type="checkbox" id="show-session-status" checked>
|
|
<label class="form-check-label" for="show-session-status">
|
|
Show Session Status
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<button class="btn btn-primary" onclick="openDeviceManager()">
|
|
Open Device Manager (Modal)
|
|
</button>
|
|
<button class="btn btn-secondary" onclick="openStandaloneDeviceManager()">
|
|
Open Device Manager (Standalone)
|
|
</button>
|
|
<button class="btn btn-danger" onclick="closeDeviceManager()">
|
|
Close Device Manager
|
|
</button>
|
|
<button class="btn btn-success" onclick="openRecoveryDeviceManager()">
|
|
Open Recovery Device Manager
|
|
</button>
|
|
|
|
<div id="device-container"></div>
|
|
|
|
<div id="error-message" class="alert alert-danger" style="display: none; margin-top: 20px;"></div>
|
|
<div id="success-message" class="alert alert-success" style="display: none; margin-top: 20px;"></div>
|
|
</div>
|
|
|
|
<script>
|
|
const SERVER_URL = 'https://fido2.amipro.me';
|
|
|
|
function showMessage(type, message) {
|
|
const element = document.getElementById(type + '-message');
|
|
element.textContent = message;
|
|
element.style.display = 'block';
|
|
setTimeout(() => {
|
|
element.style.display = 'none';
|
|
}, 5000);
|
|
}
|
|
|
|
function openDeviceManager() {
|
|
const userId = document.getElementById('user-id-input').value;
|
|
const showUserInfo = document.getElementById('show-user-info').checked;
|
|
const showSessionStatus = document.getElementById('show-session-status').checked;
|
|
|
|
try {
|
|
Fido2UIManager.renderDeviceManager({
|
|
userId: userId || null, // userId is optional now
|
|
container: '#device-container',
|
|
mode: 'modal',
|
|
serverUrl: SERVER_URL,
|
|
language: 'en-US',
|
|
features: {
|
|
showUserInfo: showUserInfo,
|
|
showSessionStatus: showSessionStatus,
|
|
showAddButton: true,
|
|
showDeleteButton: true
|
|
},
|
|
callbacks: {
|
|
onInit: function(manager) {
|
|
showMessage('success', 'Device manager initialized');
|
|
console.log('Device manager initialized:', manager);
|
|
console.log('Effective User ID:', manager.deviceManager.getEffectiveUserId());
|
|
},
|
|
onDeviceAdded: function(device) {
|
|
showMessage('success', 'Device added successfully');
|
|
console.log('Device added:', device);
|
|
},
|
|
onDeviceDeleted: function(deviceId) {
|
|
showMessage('success', 'Device deleted successfully');
|
|
console.log('Device deleted:', deviceId);
|
|
},
|
|
onDeviceListLoaded: function(devices) {
|
|
console.log('Devices loaded:', devices);
|
|
},
|
|
onUserMismatch: function(error) {
|
|
showMessage('error', 'User mismatch: ' + error);
|
|
console.error('User mismatch error:', error);
|
|
},
|
|
onError: function(error) {
|
|
showMessage('error', 'Error: ' + error.message);
|
|
console.error('Device manager error:', error);
|
|
},
|
|
onClose: function() {
|
|
console.log('Device manager closed');
|
|
}
|
|
}
|
|
});
|
|
} catch (error) {
|
|
showMessage('error', 'Failed to open device manager: ' + error.message);
|
|
console.error('Error opening device manager:', error);
|
|
}
|
|
}
|
|
|
|
function openStandaloneDeviceManager() {
|
|
const userId = document.getElementById('user-id-input').value;
|
|
const showUserInfo = document.getElementById('show-user-info').checked;
|
|
const showSessionStatus = document.getElementById('show-session-status').checked;
|
|
|
|
try {
|
|
Fido2UIManager.renderDeviceManager({
|
|
userId: userId || null, // userId is optional now
|
|
mode: 'standalone',
|
|
serverUrl: SERVER_URL,
|
|
language: 'en-US',
|
|
features: {
|
|
showUserInfo: showUserInfo,
|
|
showSessionStatus: showSessionStatus,
|
|
showAddButton: true,
|
|
showDeleteButton: true
|
|
},
|
|
callbacks: {
|
|
onInit: function(manager) {
|
|
showMessage('success', 'Standalone device manager initialized');
|
|
console.log('Standalone device manager initialized:', manager);
|
|
console.log('Effective User ID:', manager.deviceManager.getEffectiveUserId());
|
|
},
|
|
onDeviceAdded: function(device) {
|
|
showMessage('success', 'Device added successfully');
|
|
console.log('Device added:', device);
|
|
},
|
|
onDeviceDeleted: function(deviceId) {
|
|
showMessage('success', 'Device deleted successfully');
|
|
console.log('Device deleted:', deviceId);
|
|
},
|
|
onDeviceListLoaded: function(devices) {
|
|
console.log('Devices loaded:', devices);
|
|
},
|
|
onUserMismatch: function(error) {
|
|
showMessage('error', 'User mismatch: ' + error);
|
|
console.error('User mismatch error:', error);
|
|
},
|
|
onError: function(error) {
|
|
showMessage('error', 'Error: ' + error.message);
|
|
console.error('Device manager error:', error);
|
|
}
|
|
}
|
|
});
|
|
} catch (error) {
|
|
showMessage('error', 'Failed to open standalone device manager: ' + error.message);
|
|
console.error('Error opening standalone device manager:', error);
|
|
}
|
|
}
|
|
|
|
function closeDeviceManager() {
|
|
Fido2UIManager.close();
|
|
showMessage('success', 'Device manager closed');
|
|
}
|
|
|
|
function openRecoveryDeviceManager() {
|
|
const recoverySessionId = document.getElementById('user-id-input').value;
|
|
|
|
if (!recoverySessionId) {
|
|
showMessage('error', 'Please enter a recovery session ID in the User ID field');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
Fido2UIManager.renderDeviceManagerWithRecovery({
|
|
container: '#device-container',
|
|
mode: 'modal',
|
|
serverUrl: SERVER_URL,
|
|
language: 'en-US',
|
|
recoverySessionId: recoverySessionId,
|
|
features: {
|
|
showUserInfo: true,
|
|
showSessionStatus: false,
|
|
showAddButton: false,
|
|
showDeleteButton: false
|
|
},
|
|
callbacks: {
|
|
onInit: function(manager) {
|
|
showMessage('success', 'Recovery device manager initialized');
|
|
console.log('Recovery manager initialized:', manager);
|
|
console.log('Is Recovery Mode:', manager.isRecoveryMode());
|
|
console.log('Recovery User:', manager.getRecoveryUser());
|
|
},
|
|
onDeviceAdded: function(device) {
|
|
showMessage('success', 'Device recovered successfully');
|
|
console.log('Device recovered:', device);
|
|
},
|
|
onRecoveryCompleted: function(result) {
|
|
showMessage('success', 'Recovery completed for user: ' + result.user.username);
|
|
console.log('Recovery completed:', result);
|
|
},
|
|
onRecoveryCanceled: function(user) {
|
|
console.log('Recovery canceled for user:', user);
|
|
},
|
|
onError: function(error) {
|
|
showMessage('error', 'Error: ' + error.message);
|
|
console.error('Device manager error:', error);
|
|
},
|
|
onClose: function() {
|
|
console.log('Device manager closed');
|
|
}
|
|
}
|
|
});
|
|
} catch (error) {
|
|
showMessage('error', 'Failed to open recovery device manager: ' + error.message);
|
|
console.error('Error opening recovery device manager:', error);
|
|
}
|
|
}
|
|
|
|
console.log('FIDO2 Device Manager Test Page loaded');
|
|
</script>
|
|
</body>
|
|
</html>
|