last ...
This commit is contained in:
@@ -6,5 +6,7 @@ namespace xIdentityService.Constants {
|
||||
XToken,
|
||||
[StringValue ("introspection")]
|
||||
XIntrospection,
|
||||
[StringValue("XApiKey")]
|
||||
XApiKey,
|
||||
}
|
||||
}
|
||||
@@ -12,5 +12,11 @@ namespace xIdentityService.Constants
|
||||
/// </summary>
|
||||
[StringValue("requestID")]
|
||||
ConnectionId,
|
||||
|
||||
/// <summary>
|
||||
/// Api Key Header Key ...
|
||||
/// </summary>
|
||||
[StringValue("X-Api-Key")]
|
||||
ApiKey,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using xCommons.Extensions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using xIdentityService.Constants;
|
||||
|
||||
namespace xIdentityService.Extensions
|
||||
{
|
||||
public static class XRequestExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Extract ApiKey from Request Headers ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static string ExtractApiKey(HttpRequest source)
|
||||
{
|
||||
//
|
||||
var key = XHeader.ApiKey.GetStringValue();
|
||||
var result = source?.Headers?[key] ?? string.Empty;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract Client Id of Specified Request ....
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static string ExtractClientIP(HttpRequest source)
|
||||
{
|
||||
//
|
||||
var result = source?.HttpContext.Connection.RemoteIpAddress?.ToString();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user