XAF module for API key generation and management with expiration support.
$ dotnet add package Xeku.ApiKeyA standalone XAF module for generating, managing, and validating API Keys.
RandomNumberGenerator (256-bit) with SHA256 hashing.IsAdministrative role can manage keys.sequenceDiagram
Admin->>XAF UI: Click Generate API Key
XAF UI->>ApiKeyService: Request generation (Expiration)
ApiKeyService->>CSPRNG: Generate 32 random bytes
CSPRNG-->>ApiKeyService: Random Bytes
ApiKeyService->>SHA256: Hash bytes
SHA256-->>ApiKeyService: Key Hash
ApiKeyService->>Database: Save ApiKeyInfo (Hash, Expiry)
ApiKeyService-->>XAF UI: Return Plaintext Key (Only once)
XAF UI-->>Admin: Show Key & Copy to Clipboard
dotnet add package Xeku.ApiKey
// In module constructor
RequiredModuleTypes.Add(typeof(Xeku.ApiKey.ApiKeyModule));
IsAdministrative role).[!WARNING] The key is shown only once and cannot be retrieved later.
Use CachedApiKeyValidator for improved validation performance:
// Create cached validator
var cachedValidator = new CachedApiKeyValidator(validator, cacheService);
cachedValidator.CacheDuration = TimeSpan.FromMinutes(10);
MIT License