Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Replaced AuthorizeAttribute check with ApiGroupAttribute in IsApiFrontAuthenticated() to determine API group membership. (#688)

Taraweesh5ff350f0e2d5
diff --git a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs
index bf7e9bfe5..2c86f0fa7 100644
--- a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs
+++ b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs
@@ -3,6 +3,8 @@ using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Domain.Customers;
using Grand.Infrastructure.Configuration;
+using Grand.SharedKernel.Attributes;
+using Grand.SharedKernel.Extensions;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
@@ -61,8 +63,8 @@ public class ApiAuthenticationService : IApiAuthenticationService
var endpoint = _httpContextAccessor.HttpContext.GetEndpoint();
if (endpoint == null) return false;
- var authorizeAttributes = endpoint.Metadata.GetOrderedMetadata<AuthorizeAttribute>();
- return authorizeAttributes.Any(attr => attr.AuthenticationSchemes?.Contains(FrontendAPIConfig.AuthenticationScheme) == true);
+ var apiGroupAttr = endpoint.Metadata.GetOrderedMetadata<ApiGroupAttribute>();
+ return apiGroupAttr.Any(attr => attr.GroupName == ApiConstants.ApiGroupNameV2);
}