Xeku.ApiKey 0.0.0.7

dotnet add package Xeku.ApiKey --version 0.0.0.7
                    
NuGet\Install-Package Xeku.ApiKey -Version 0.0.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xeku.ApiKey" Version="0.0.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xeku.ApiKey" Version="0.0.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Xeku.ApiKey" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xeku.ApiKey --version 0.0.0.7
                    
#r "nuget: Xeku.ApiKey, 0.0.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xeku.ApiKey@0.0.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xeku.ApiKey&version=0.0.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Xeku.ApiKey&version=0.0.0.7
                    
Install as a Cake Tool

Xeku.ApiKey

A standalone XAF module for generating, managing, and validating API Keys.

繁體中文文檔

Features

  • Secure Key Generation: Uses RandomNumberGenerator (256-bit) with SHA256 hashing.
  • Key Expiration: Configurable expiration time (5 minutes to 90 days).
  • Admin Only: Only users with IsAdministrative role can manage keys.
  • One Key Per User: Generating a new key automatically revokes the old one.
  • Usage Tracking: Records creation time and last usage time.

Architecture

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

Installation

1. NuGet Package

dotnet add package Xeku.ApiKey

2. Add Module Reference

// In module constructor
RequiredModuleTypes.Add(typeof(Xeku.ApiKey.ApiKeyModule));

Usage

Generate API Key

  1. Open any user's DetailView (requires IsAdministrative role).
  2. Click "Generate API Key" in the toolbar.
  3. Select expiration: 5 min / 30 min / 1 day / 30 days / 60 days / 90 days.
  4. Popup displays generated key (auto-copied to clipboard).

The key is shown only once and cannot be retrieved later.

Cache Integration

Use CachedApiKeyValidator for improved validation performance:

// Create cached validator
var cachedValidator = new CachedApiKeyValidator(validator, cacheService);
cachedValidator.CacheDuration = TimeSpan.FromMinutes(10);

AI Agent Integration

Suggested Context

  • Business Rule: API Keys should be used for all external server-to-server communications.
  • Security Policy: Always set the shortest possible expiration for temporary keys.

Common Tasks

  • "How do I check if an API key is valid for user 'X'?"
  • "Revoke all API keys that are expiring in the next 24 hours."

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Xeku.ApiKey:

Package Downloads
Xeku.ApiKey.WebApi

API key authentication handler for XAF Web API, integrating with XAF Security System.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.0.7 105 1/28/2026
0.0.0.6 118 1/21/2026
0.0.0.5 114 1/15/2026
0.0.0.4 111 1/13/2026
0.0.0.3 135 1/9/2026
0.0.0.2 122 1/8/2026