@page "/apikeys" @attribute [Authorize(Policy = AdminUiPolicies.FleetAdmin)] @rendermode RenderMode.InteractiveServer @using ZB.MOM.WW.OtOpcUa.Configuration.Entities @using ZB.MOM.WW.OtOpcUa.Core.Authorization @using ZB.MOM.WW.OtOpcUa.AdminUI.Components.Shared.Raw @using ZB.MOM.WW.OtOpcUa.AdminUI.ApiKeyAck @inject IApiKeyAdminService Keys @inject IApiKeyGalaxyAckIdentityService AckIdentities

OPC UA API keys

@if (_created is not null) { } @if (!string.IsNullOrWhiteSpace(_error)) { }
Create a key
@if (_ackEditKeyId is not null) {
Galaxy alarm-ack identity — key @_ackEditKeyId
Native Galaxy alarm acknowledges from sessions using this key authenticate as this Galaxy account, and the Historian records it as the operator. Stored encrypted in the Secrets store (otopcua/apikeys/@(_ackEditKeyId)/galaxy-ack-*), never in the database. Keys without an identity use the Galaxy driver's fallback account; with neither, acknowledges are refused. On a split admin/driver topology the two secrets must also exist on the driver nodes.
@if (_ackIdentities.ContainsKey(_ackEditKeyId)) { }
}
Keys
@if (_keys is null) {
Loading…
} else if (_keys.Count == 0) {
No keys yet. Until one exists, only anonymous sessions can connect.
} else { @foreach (var k in _keys) { }
Name Principal Key id Status Galaxy ack identity Created (UTC) Expires (UTC)
@k.Name @k.Principal @k.ApiKeyId @if (!k.Enabled) { revoked } else if (k.ExpiresUtc is { } e && e <= DateTime.UtcNow) { expired } else { active } @if (_ackIdentities.TryGetValue(k.ApiKeyId, out var ackId)) { @ackId } else { driver fallback } @k.CreatedUtc.ToString("yyyy-MM-dd HH:mm") @(k.ExpiresUtc?.ToString("yyyy-MM-dd") ?? "—")
}
@code { [CascadingParameter] private Task? AuthState { get; set; } private IReadOnlyList? _keys; private IReadOnlyDictionary _ackIdentities = new Dictionary(); // Galaxy ack identity editor (lmxopcua#749). The password lives in component state only while the // editor is open and is cleared on save/cancel; it is never rendered back. private string? _ackEditKeyId; private string _ackUser = ""; private string _ackDomain = ""; private string _ackPassword = ""; private string _newName = ""; private string _newPrincipal = ""; private DateTime? _newExpires; private string? _created; private string? _error; private bool _busy; // Delete is irreversible (the key stops authenticating at once), so it goes through a confirm dialog // that names the key rather than firing from the row button. private bool _confirmDeleteVisible; private string? _confirmDeleteId; private string _confirmDeleteMessage = ""; protected override async Task OnInitializedAsync() => await ReloadAsync(); private async Task ReloadAsync() { try { _keys = await Keys.ListAsync(default); try { _ackIdentities = await AckIdentities.ListAsync(default); } catch (Exception ex) { _ackIdentities = new Dictionary(); _error = $"Galaxy ack identities unavailable: {ex.Message}"; } // The one-time banner is only meaningful while its key exists; the credential is // otua__, so drop it once no listed key matches (deleted here or elsewhere). if (_created is not null && !_keys.Any(k => _created.StartsWith($"otua_{k.ApiKeyId}_", StringComparison.Ordinal))) { _created = null; } } catch (Exception ex) { _error = ex.Message; _keys = []; } } private async Task CreateAsync() { _busy = true; _error = null; _created = null; try { // Shown once, held only in this component's state. There is no way to recover it afterwards // — the server stores a hash — so it is deliberately not written anywhere else. _created = await Keys.CreateAsync( _newName, _newPrincipal, // A date-only input means midnight; treat it as UTC rather than local so an operator // near a timezone boundary does not get a key that expired before it was issued. _newExpires is { } d ? DateTime.SpecifyKind(d, DateTimeKind.Utc) : null, notes: null, default); _newName = ""; _newPrincipal = ""; _newExpires = null; await ReloadAsync(); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private async Task SetEnabledAsync(string apiKeyId, bool enabled) { _busy = true; _error = null; try { await Keys.SetEnabledAsync(apiKeyId, enabled, default); await ReloadAsync(); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private void RequestDelete(ApiKey key) { _confirmDeleteId = key.ApiKeyId; _confirmDeleteMessage = $"Permanently delete API key '{key.Name}' ({key.ApiKeyId})? Clients using it will stop authenticating immediately. This cannot be undone."; _confirmDeleteVisible = true; } private async Task ConfirmDeleteAsync() { if (_confirmDeleteId is { } id) { await DeleteAsync(id); } } private async Task DeleteAsync(string apiKeyId) { _busy = true; _error = null; try { await Keys.DeleteAsync(apiKeyId, default); // A deleted key's ack identity must not linger in the Secrets store. await AckIdentities.ClearAsync(apiKeyId, await ActorAsync(), default); if (_ackEditKeyId == apiKeyId) CloseAckEditor(); await ReloadAsync(); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private void OpenAckEditor(string apiKeyId) { _ackEditKeyId = apiKeyId; _ackPassword = ""; if (_ackIdentities.TryGetValue(apiKeyId, out var current)) { var slash = current.IndexOf('\\'); _ackDomain = slash < 0 ? "" : current[..slash]; _ackUser = slash < 0 ? current : current[(slash + 1)..]; } else { _ackUser = ""; _ackDomain = ""; } } private void CloseAckEditor() { _ackEditKeyId = null; _ackUser = ""; _ackDomain = ""; _ackPassword = ""; } private async Task SaveAckIdentityAsync() { if (_ackEditKeyId is not { } id) return; _busy = true; _error = null; try { await AckIdentities.SetAsync(id, _ackUser, _ackDomain, _ackPassword, await ActorAsync(), default); CloseAckEditor(); await ReloadAsync(); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private async Task ClearAckIdentityAsync() { if (_ackEditKeyId is not { } id) return; _busy = true; _error = null; try { await AckIdentities.ClearAsync(id, await ActorAsync(), default); CloseAckEditor(); await ReloadAsync(); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private async Task ActorAsync() { var user = AuthState is null ? null : (await AuthState).User; return user?.Identity?.Name is { Length: > 0 } name ? name : "unknown"; } }