From b7fba89157a72dfac6fde5f45b2d2c1459f972f0 Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Sun, 4 Oct 2026 18:11:46 +0330 Subject: [PATCH] last ... --- Configurations/XApiKeyConfiguration.cs | 33 ++++++++++++++++++++++++++ DbContext/XIdentityDbContext.cs | 27 ++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 Configurations/XApiKeyConfiguration.cs diff --git a/Configurations/XApiKeyConfiguration.cs b/Configurations/XApiKeyConfiguration.cs new file mode 100644 index 0000000..f7dae46 --- /dev/null +++ b/Configurations/XApiKeyConfiguration.cs @@ -0,0 +1,33 @@ +namespace xIds.Configurations +{ + /// + /// Configuration settings for API Key management, including expiration, rate limiting, and audit logging. + /// + public class XApiKeyConfiguration + { + /// + /// Default expiration in minutes (e.g., 43200 = 30 days) + /// + public int DefaultExpirationMinutes { get; set; } = 43200; + + /// + /// Maximum allowed expiration in minutes (e.g., 525600 = 1 year) + /// + public int MaxExpirationMinutes { get; set; } = 525600; + + /// + /// Maximum ApiKeys per Application + /// + public int MaxKeysPerApplication { get; set; } = 10; + + /// + /// Enable audit logging + /// + public bool EnableAuditLog { get; set; } = true; + + /// + /// Default rate limit (requests per minute) + /// + public int DefaultRateLimit { get; set; } = 60; + } +} \ No newline at end of file diff --git a/DbContext/XIdentityDbContext.cs b/DbContext/XIdentityDbContext.cs index 2b9628f..7d01345 100644 --- a/DbContext/XIdentityDbContext.cs +++ b/DbContext/XIdentityDbContext.cs @@ -1,9 +1,9 @@ -using Microsoft.AspNetCore.Identity; -using Microsoft.AspNetCore.Identity.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore; using xIdentityModels; using xIdentityModels.Models; using xIdentityModels.Navigations; +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using Microsoft.AspNetCore.Identity.EntityFrameworkCore; namespace xIds.DbContext { @@ -13,7 +13,10 @@ namespace xIds.DbContext #region Props/DbSets ... public DbSet Tokens { get; set; } public DbSet Devices { get; set; } + public DbSet ApiKeys { get; set; } public DbSet Avatars { get; set; } + public DbSet ApiKeyUsage { get; set; } + public DbSet Applications { get; set; } public DbSet BannedDevices { get; set; } public DbSet Followers { get; set; } public DbSet Followings { get; set; } @@ -52,6 +55,24 @@ namespace xIds.DbContext .HasForeignKey(ur => ur.UserId) .IsRequired(); }); + + // + // Configure XApplication ... + modelBuilder.Entity(e => + { + e.HasIndex(a => a.Name).IsUnique(); + e.HasMany(a => a.ApiKeys) + .WithOne(k => k.Application) + .HasForeignKey(k => k.ApplicationId); + }); + + // + // Configure XApiKey ... + modelBuilder.Entity(e => + { + e.HasIndex(k => k.KeyHash).IsUnique(); + e.HasIndex(k => k.ExpiresAt); + }); } } } \ No newline at end of file