2020-03-19 19:11:15 +09:00
@namespace BTCPayServer.Client
2022-07-15 05:38:33 +02:00
@using BTCPayServer.Abstractions.Models
2023-03-08 17:57:36 +09:00
@inject BTCPayServer.Security.ContentSecurityPolicies Csp
2022-01-07 12:32:00 +09:00
@model BTCPayServer.Controllers.UIManageController.ApiKeysViewModel
2020-02-24 14:36:15 +01:00
@{
2023-03-08 17:57:36 +09:00
ViewData.SetActivePage(ManageNavPages.APIKeys, "API Keys");
Csp.UnsafeEval();
2020-02-24 14:36:15 +01:00
}
2022-01-17 17:19:27 -08:00
2024-06-19 15:23:10 +02:00
<div class="sticky-header">
2024-07-25 22:46:02 +09:00
<h2 text-translate="true">@ViewData["Title"]</h2>
2024-07-25 15:23:28 +09:00
<a id="page-primary" class="btn btn-primary" asp-action="AddApiKey">
2024-06-19 15:23:10 +02:00
Generate Key
</a>
</div>
<partial name="_StatusMessage" />
2022-01-27 03:56:46 +01:00
<div class="row">
2022-04-08 11:58:01 +02:00
<div class="col-xl-10 col-xxl-constrain">
2022-01-27 03:56:46 +01:00
<p>
The <a asp-controller="UIHome" asp-action="SwaggerDocs" target="_blank">BTCPay Server Greenfield API</a> offers programmatic access to your instance. You can manage your BTCPay
Server (e.g. stores, invoices, users) as well as automate workflows and integrations (see <a href="https://docs.btcpayserver.org/Development/GreenFieldExample/" rel="noreferrer noopener">use case examples</a>).
For that you need the API keys, which can be generated here. Find more information in the <a href="@Url.Action("SwaggerDocs", "UIHome")#section/Authentication" target="_blank" rel="noreferrer noopener">API authentication docs</a>.
</p>
@if (Model.ApiKeyDatas.Any())
{
<table class="table table-lg">
<thead>
<tr>
<th>Label</th>
<th class="w-125px">Key</th>
<th>Permissions</th>
<th class="text-end">Actions</th>
</tr>
</thead>
<tbody>
@{
var index = 0;
}
@foreach (var keyData in Model.ApiKeyDatas)
{
<tr>
<td>@keyData.Label</td>
<td>
<code class="hide-when-js">@keyData.Id</code>
2023-03-19 21:43:38 +01:00
<button type="button" class="btn btn-link only-for-js p-0" data-reveal-btn>Reveal</button>
<div hidden class="gap-2 align-items-center">
<code>@keyData.Id</code>
<button type="button" class="btn btn-link d-flex p-0" data-clipboard="@keyData.Id">
2024-05-20 01:57:46 +02:00
<vc:icon symbol="actions-copy" />
2023-03-19 21:43:38 +01:00
</button>
2022-01-27 03:56:46 +01:00
</div>
</td>
<td>
@{
var permissions = keyData.GetBlob().Permissions;
}
@if (!permissions.Any())
2021-11-12 20:22:04 -08:00
{
2023-12-13 10:53:37 +01:00
<span class="info-note text-warning">
<vc:icon symbol="warning"/>
No permissions
</span>
2021-11-12 20:22:04 -08:00
}
2022-01-27 03:56:46 +01:00
else
{
2023-03-19 21:43:38 +01:00
@foreach (var permission in Permission.ToPermissions(permissions).Select(c => c.ToString()).Distinct().ToArray())
{
<div><code class="text-break">@permission</code></div>
}
2022-01-27 03:56:46 +01:00
}
</td>
2023-03-19 21:43:38 +01:00
<td>
<div class="d-flex align-items-center justify-content-end gap-1">
<a asp-action="DeleteAPIKey" asp-route-id="@keyData.Id" asp-controller="UIManage" data-bs-toggle="modal" data-bs-target="#ConfirmModal" data-description="Any application using the API key <strong>@Html.Encode(keyData.Label ?? keyData.Id)</strong> will immediately lose access." data-confirm-input="DELETE">Delete</a>
<span>-</span>
<button type="button" class="btn btn-link only-for-js p-0" data-qr="@index">Show QR</button>
</div>
2022-01-27 03:56:46 +01:00
</td>
</tr>
index++;
}
</tbody>
</table>
}
</div>
</div>
2021-01-07 09:56:35 +01:00
2021-09-07 04:55:53 +02:00
<partial name="_Confirm" model="@(new ConfirmModel("Delete API key", "Any application using the API key will immediately lose access.", "Delete"))" />
2021-11-12 20:22:04 -08:00
<partial name="ShowQR" />
2021-09-07 04:55:53 +02:00
2021-05-19 04:39:27 +02:00
@section PageHeadContent {
2021-11-12 20:22:04 -08:00
<link href="~/vendor/vue-qrcode-reader/vue-qrcode-reader.css" rel="stylesheet" asp-append-version="true" />
2021-05-19 04:39:27 +02:00
}
@section PageFootContent {
2022-10-20 11:17:42 +09:00
<script src="~/vendor/vuejs/vue.min.js" asp-append-version="true"></script>
<script src="~/vendor/vue-qrcode/vue-qrcode.min.js" asp-append-version="true"></script>
<script src="~/vendor/ur-registry/urlib.min.js" asp-append-version="true"></script>
<script src="~/vendor/vue-qrcode-reader/VueQrcodeReader.umd.min.js" asp-append-version="true"></script>
2021-09-07 04:55:53 +02:00
<script>
2023-03-19 21:43:38 +01:00
delegate('click', '[data-reveal-btn]', e => {
const $container = e.target.parentElement.querySelector('[hidden]')
e.target.setAttribute('hidden', 'true')
$container.removeAttribute('hidden')
$container.classList.add('d-inline-flex')
})
2021-09-07 04:55:53 +02:00
document.addEventListener("DOMContentLoaded", function () {
2022-08-31 12:27:06 +02:00
const apiKeys = @Safe.Json(Model.ApiKeyDatas.Select(data => new
2023-03-19 21:43:38 +01:00
{
ApiKey = data.Id,
Host = Context.Request.GetAbsoluteRoot()
}));
2022-08-31 12:27:06 +02:00
const qrApp = initQRShow({ title: "API Key QR" });
delegate("click", "button[data-qr]", e => {
e.preventDefault();
const { qr } = e.target.dataset;
const data = apiKeys[qr];
qrApp.showData(JSON.stringify(data));
2021-09-07 04:55:53 +02:00
});
2021-01-07 09:56:35 +01:00
});
2021-09-07 04:55:53 +02:00
</script>
2022-01-07 12:32:00 +09:00
}