122 lines
4.6 KiB
Plaintext
122 lines
4.6 KiB
Plaintext
<% title = 'Admin - OAuth Clients'; %>
|
|
<% include ../layouts/main.ejs %>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<ul class="nav nav-tabs mb-3">
|
|
<li class="nav-item"><a class="nav-link" href="/admin/users">Users</a></li>
|
|
<li class="nav-item"><a class="nav-link active" href="/admin/clients">OAuth Clients</a></li>
|
|
</ul>
|
|
|
|
<div class="card shadow">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<span>OAuth Clients (<%= clients.length %>)</span>
|
|
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#createClientModal">+ Add Client</button>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<table class="table table-striped mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Client ID</th>
|
|
<th>Confidential</th>
|
|
<th>Grants</th>
|
|
<th>Owner</th>
|
|
<th>Created</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<% clients.forEach(function(c) { %>
|
|
<tr>
|
|
<td><%= c.name %></td>
|
|
<td><code><%= c.clientId %></code></td>
|
|
<td><%= c.isConfidential ? 'Yes' : 'No' %></td>
|
|
<td><%= c.grants.join(', ') %></td>
|
|
<td><%= c.owner ? c.owner.email : '-' %></td>
|
|
<td><%= new Date(c.createdAt).toLocaleDateString() %></td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-danger" onclick="deleteClient('<%= c.id %>')">Delete</button>
|
|
</td>
|
|
</tr>
|
|
<% }); %>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="modal fade" id="createClientModal" tabindex="-1">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Create OAuth Client</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="createClientForm">
|
|
<div class="mb-3">
|
|
<label class="form-label">Name</label>
|
|
<input type="text" class="form-control" id="clientName" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Client ID</label>
|
|
<input type="text" class="form-control" id="clientId" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Description</label>
|
|
<input type="text" class="form-control" id="clientDesc">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Redirect URIs (comma separated)</label>
|
|
<input type="text" class="form-control" id="clientUris" placeholder="http://localhost:5173/callback">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label class="form-label">Grants (comma separated)</label>
|
|
<input type="text" class="form-control" id="clientGrants" value="authorization_code,refresh_token">
|
|
</div>
|
|
<div class="mb-3 form-check">
|
|
<input type="checkbox" class="form-check-input" id="clientConfidential" checked>
|
|
<label class="form-check-label">Confidential</label>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button class="btn btn-primary" onclick="createClient()">Create</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const token = localStorage.getItem('access_token');
|
|
if (!token) window.location.href = '/login';
|
|
|
|
async function createClient() {
|
|
const res = await fetch('/api/admin/clients', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` },
|
|
body: JSON.stringify({
|
|
name: document.getElementById('clientName').value,
|
|
clientId: document.getElementById('clientId').value,
|
|
description: document.getElementById('clientDesc').value,
|
|
redirectUris: document.getElementById('clientUris').value.split(',').map(s => s.trim()),
|
|
grants: document.getElementById('clientGrants').value.split(',').map(s => s.trim()),
|
|
isConfidential: document.getElementById('clientConfidential').checked,
|
|
}),
|
|
});
|
|
if (res.ok) location.reload();
|
|
else alert('Failed to create client');
|
|
}
|
|
|
|
async function deleteClient(id) {
|
|
if (!confirm('Delete this client?')) return;
|
|
const res = await fetch(`/api/admin/clients/${id}`, {
|
|
method: 'DELETE',
|
|
headers: { 'Authorization': `Bearer ${token}` },
|
|
});
|
|
if (res.ok) location.reload();
|
|
else alert('Failed to delete client');
|
|
}
|
|
</script>
|