diff --git a/Providers/XApiKeyAccessAttribute.cs b/Providers/XApiKeyAccessAttribute.cs
index aebfca1..22aac55 100644
--- a/Providers/XApiKeyAccessAttribute.cs
+++ b/Providers/XApiKeyAccessAttribute.cs
@@ -13,6 +13,7 @@ using xIdentityService.Constants;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Authorization;
+using System.Threading;
namespace xIds.Providers
{
@@ -56,7 +57,10 @@ namespace xIds.Providers
///
///
///
- private async Task OnAuthorizationAsync(AuthorizationFilterContext context)
+ private async Task OnAuthorizationAsync(
+ AuthorizationFilterContext context,
+ CancellationToken cancellationToken = default
+ )
{
//
// Access HttpContext ...
@@ -109,13 +113,20 @@ namespace xIds.Providers
//
// Extract Client IP ...
var clientIP = http.Request.HttpContext.Connection.RemoteIpAddress?.ToString();
+ var scopes =
+ !Scopes.HasChild()
+ ? string.Empty
+ : Scopes.ToListString();
//
// Validating ApiKey ...
var validationResult = await applicationProvider
.ValidateApiKey(
apiKey: apiKey,
- clientIP: clientIP
+ userInfo: null,
+ clientIP: clientIP,
+ requiredScope: scopes,
+ cancellationToken: cancellationToken
);
if (validationResult.Errors.HasChild())
{
diff --git a/Providers/XApplicationProvider/XApplicationProvider+ApiKey.cs b/Providers/XApplicationProvider/XApplicationProvider+ApiKey.cs
index 0bc68b0..a6542b0 100644
--- a/Providers/XApplicationProvider/XApplicationProvider+ApiKey.cs
+++ b/Providers/XApplicationProvider/XApplicationProvider+ApiKey.cs
@@ -136,7 +136,7 @@ namespace xIds.Providers
// Validate ...
if (
id != item.Id ||
- !id.IsDefaultGuid() ||
+ id.IsDefaultGuid() ||
!item.IsValidForAdd() ||
item.IsNullOrDefault() ||
userInfo.IsNullOrDefault()
diff --git a/Providers/XApplicationProvider/XApplicationProvider+Custom.cs b/Providers/XApplicationProvider/XApplicationProvider+Custom.cs
index 4a0e7a6..21c39fa 100644
--- a/Providers/XApplicationProvider/XApplicationProvider+Custom.cs
+++ b/Providers/XApplicationProvider/XApplicationProvider+Custom.cs
@@ -303,8 +303,10 @@ namespace xIds.Providers
//
newExpiration = TimeSpan
.FromMinutes(apiKeyConfiguration.DefaultExpirationMinutes);
- expiredDate = DateTime.UtcNow.Add(newExpiration.Value);
}
+ expiredDate = DateTime.UtcNow.Add(newExpiration.Value);
+
+ //
if (!expiredDate.HasValue)
{
XException.InvalidArgs.Throw();
@@ -496,6 +498,12 @@ namespace xIds.Providers
result.Errors.Add("ApiKey Rate Limit Reached ...");
}
+ //
+ var requiredScopes =
+ requiredScope.IsNullOrEmpty()
+ ? []
+ : requiredScope.ParseListString();
+
//
// Audit Log ...
@@ -507,7 +515,9 @@ namespace xIds.Providers
var isScopeValid =
!allowedScopes.HasChild() ||
requiredScope.IsNullOrEmpty() ||
- allowedScopes.Contains(requiredScope);
+ requiredScopes
+ .All(ts => allowedScopes
+ .Any(asc => asc.ToNormalString() == ts.ToNormalString()));
var isScopeIpValid =
isIpValid &&
isScopeValid