From a0feb15cad0f8ba9c33e238189fd4d9c3ccf782f Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Tue, 6 Oct 2026 17:46:59 +0330 Subject: [PATCH] last ... --- Constants/XAuthenticationScheme.cs | 2 ++ Constants/XHeader.cs | 6 ++++++ Extensions/XRequestExtensions.cs | 34 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 Extensions/XRequestExtensions.cs diff --git a/Constants/XAuthenticationScheme.cs b/Constants/XAuthenticationScheme.cs index 32be81b..c5c19e4 100644 --- a/Constants/XAuthenticationScheme.cs +++ b/Constants/XAuthenticationScheme.cs @@ -6,5 +6,7 @@ namespace xIdentityService.Constants { XToken, [StringValue ("introspection")] XIntrospection, + [StringValue("XApiKey")] + XApiKey, } } \ No newline at end of file diff --git a/Constants/XHeader.cs b/Constants/XHeader.cs index ddceaa6..642f557 100644 --- a/Constants/XHeader.cs +++ b/Constants/XHeader.cs @@ -12,5 +12,11 @@ namespace xIdentityService.Constants /// [StringValue("requestID")] ConnectionId, + + /// + /// Api Key Header Key ... + /// + [StringValue("X-Api-Key")] + ApiKey, } } \ No newline at end of file diff --git a/Extensions/XRequestExtensions.cs b/Extensions/XRequestExtensions.cs new file mode 100644 index 0000000..a73070b --- /dev/null +++ b/Extensions/XRequestExtensions.cs @@ -0,0 +1,34 @@ +using xCommons.Extensions; +using Microsoft.AspNetCore.Http; +using xIdentityService.Constants; + +namespace xIdentityService.Extensions +{ + public static class XRequestExtensions + { + /// + /// Extract ApiKey from Request Headers ... + /// + /// + /// + public static string ExtractApiKey(HttpRequest source) + { + // + var key = XHeader.ApiKey.GetStringValue(); + var result = source?.Headers?[key] ?? string.Empty; + return result; + } + + /// + /// Extract Client Id of Specified Request .... + /// + /// + /// + public static string ExtractClientIP(HttpRequest source) + { + // + var result = source?.HttpContext.Connection.RemoteIpAddress?.ToString(); + return result; + } + } +} \ No newline at end of file