This commit is contained in:
2026-11-28 00:08:02 +03:30
parent 9d913146e1
commit 49483d1d39
2 changed files with 17 additions and 34 deletions
+16 -17
View File
@@ -21,7 +21,7 @@ namespace xIds.Providers
AllowMultiple = false, AllowMultiple = false,
Inherited = true Inherited = true
)] )]
public class XApiKeyAccessAttribute : AuthorizeAttribute, IAuthorizationFilter public class XApiKeyAccessAttribute : AuthorizeAttribute, IAsyncAuthorizationFilter
{ {
/// <summary> /// <summary>
/// Optional allowed scopes. If empty, no scope enforcement. /// Optional allowed scopes. If empty, no scope enforcement.
@@ -46,21 +46,7 @@ namespace xIds.Providers
/// Authorization Filtering ... /// Authorization Filtering ...
/// </summary> /// </summary>
/// <param name="context"></param> /// <param name="context"></param>
public void OnAuthorization(AuthorizationFilterContext context) public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
Task.FromResult(OnAuthorizationAsync(context));
}
/// <summary>
/// Handle Authorization Filtering Using Tasks ...
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task OnAuthorizationAsync(
AuthorizationFilterContext context,
CancellationToken cancellationToken = default
)
{ {
// //
// Access HttpContext ... // Access HttpContext ...
@@ -125,7 +111,7 @@ namespace xIds.Providers
userInfo: null, userInfo: null,
clientIP: clientIP, clientIP: clientIP,
requiredScope: scopes, requiredScope: scopes,
cancellationToken: cancellationToken cancellationToken: default
); );
if (validationResult.Errors.HasChild()) if (validationResult.Errors.HasChild())
{ {
@@ -155,5 +141,18 @@ namespace xIds.Providers
context.Result = new UnauthorizedObjectResult(error); context.Result = new UnauthorizedObjectResult(error);
} }
} }
/// <summary>
/// Handle Authorization Filtering Using Tasks ...
/// </summary>
/// <param name="context"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
private async Task OnAuthorizationAsync(
AuthorizationFilterContext context,
CancellationToken cancellationToken = default
)
{
}
} }
} }
+1 -17
View File
@@ -133,23 +133,7 @@ namespace xIds
// //
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
// endpoints.MapDefaultControllerRoute();
// endpoints.MapDefaultControllerRoute();
//
try
{
endpoints.MapDefaultControllerRoute();
}
catch (ReflectionTypeLoadException ex)
{
foreach (var loaderException in ex.LoaderExceptions)
{
// Log or inspect the specific error, e.g., "Could not load file or assembly..."
Console.WriteLine(loaderException?.Message);
}
throw; // Re-throw to preserve the original behavior
}
}); });
} }
} }