Class SystemApiKeyManagementService
Delegates system API key operations to IApiKeyAdministrationService, stamping the creating user's identity from their claims rather than trusting a caller-supplied value, and enforcing owner-scoping for personal system keys.
public class SystemApiKeyManagementService : ISystemApiKeyManagementService
- Inheritance
-
SystemApiKeyManagementService
- Implements
- Inherited Members
Remarks
Split out of ApiKeyManagementService: these operations belong to no team, so they are registered
as a system service. Keeping them alongside the team operations is what previously let one
authorization policy be applied to both.
A personal system key is owned by a user, not a team member. The owner is the caller's user key, which is the same value as their member key in any team — so the member key is used when a team is selected, and the user store is asked otherwise.
Constructors
SystemApiKeyManagementService(IApiKeyAdministrationService, IHttpContextAccessor, IOptions<ApiKeyOptions>, IUserService)
public SystemApiKeyManagementService(IApiKeyAdministrationService inner, IHttpContextAccessor httpContextAccessor = null, IOptions<ApiKeyOptions> options = null, IUserService userService = null)
Parameters
innerIApiKeyAdministrationServicehttpContextAccessorIHttpContextAccessoroptionsIOptions<ApiKeyOptions>userServiceIUserService
Methods
CreateSystemKeyAsync(string, string[], DateTime?, bool)
Creates a system key. When personal is true the key belongs to the caller, who must
be a signed-in user; a caller can only ever create a key owned by themselves.
public Task<IApiKey> CreateSystemKeyAsync(string name, string[] scopes, DateTime? expiryDate = null, bool personal = false)
Parameters
Returns
Remarks
SystemKeys decides what is allowed: Shared
refuses personal with an InvalidOperationException, and
Personal makes every key personal whatever personal says.
DeleteSystemKeyAsync(string)
public Task DeleteSystemKeyAsync(string key)
Parameters
keystring
Returns
GetSystemKeysAsync(PrivateKeyScope)
Returns the system keys for the caller. Shared keys are always included; personal keys are included
per personalKeys, intersected with the caller's entitlement (Mine = the
caller's own; All = own, plus everyone's for an Oversee holder).
The default lists shared keys only, as before personal system keys existed.
public IAsyncEnumerable<IApiKey> GetSystemKeysAsync(PrivateKeyScope personalKeys = PrivateKeyScope.None)
Parameters
personalKeysPrivateKeyScope
Returns
LockSystemKeyAsync(string)
public Task LockSystemKeyAsync(string key)
Parameters
keystring
Returns
RefreshSystemKeyAsync(string)
public Task<IApiKey> RefreshSystemKeyAsync(string key)
Parameters
keystring
Returns
Remarks
A personal key can be refreshed only by its owner or an Oversee holder; the same goes for lock, disable and delete.
SetSystemKeyDisabledAsync(string, bool)
Disables the key, or enables it again. A disabled key is refused at authentication but keeps its name, scopes, roles, tags and history — the reversible alternative to DeleteKeyAsync(string, string).
public Task SetSystemKeyDisabledAsync(string key, bool disabled)
Parameters
Returns
Remarks
Refreshing a disabled key does not enable it. A refresh mints a new secret; it is not a decision to trust the key again, and the usual reason to refresh is the same suspected leak that prompted the disable.