Adding security
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using LCU.Library.Internal.ApiSecurity.Enums;
|
||||
|
||||
namespace LCU.Library.Internal.ApiSecurity.Models;
|
||||
|
||||
public class ApiSecurityConfiguration
|
||||
{
|
||||
public ApiKeyAuthenticationFailureBehavior ApiKeyAuthenticationFailureBehavior { get; set; }
|
||||
|
||||
[Required]
|
||||
public Dictionary<string, string> ExternalApiKeySet { get; set; }
|
||||
|
||||
[Required]
|
||||
public Dictionary<string, string> InternalApiKeySet { get; set; }
|
||||
|
||||
public ApiSecurityConfiguration(ApiKeyAuthenticationFailureBehavior apiKeyAuthenticationFailureBehavior = ApiKeyAuthenticationFailureBehavior.Error)
|
||||
{
|
||||
ApiKeyAuthenticationFailureBehavior = apiKeyAuthenticationFailureBehavior;
|
||||
ExternalApiKeySet = new Dictionary<string, string>();
|
||||
InternalApiKeySet = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
public string ExtractApiKey(string clientKeyValue, ApiKeySetName keySetName)
|
||||
{
|
||||
string extractedApiKey = "";
|
||||
|
||||
if (keySetName == ApiKeySetName.InternalKeySet && !InternalApiKeySet.TryGetValue(clientKeyValue, out extractedApiKey))
|
||||
{
|
||||
throw new Exception("Your Internal Api Key is missing");
|
||||
}
|
||||
|
||||
if (keySetName == ApiKeySetName.ExternalKeySet && !ExternalApiKeySet.TryGetValue(clientKeyValue, out extractedApiKey))
|
||||
{
|
||||
throw new Exception("Your External Api Key is missing");
|
||||
}
|
||||
return extractedApiKey;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user