diff --git a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs index bf7e9bfe5..04cbfaabf 100644 --- a/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs +++ b/src/Business/Grand.Business.Authentication/Services/ApiAuthenticationService.cs @@ -5,7 +5,6 @@ using Grand.Infrastructure.Configuration; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.Net.Http.Headers; @@ -35,7 +34,7 @@ public virtual async Task GetAuthenticatedCustomer() if (string.IsNullOrEmpty(authHeader)) return null; - if (IsApiFrontAuthenticated()) + if (await IsApiFrontAuthenticated()) { customer = await ApiCustomer(); return customer; @@ -56,13 +55,10 @@ public virtual async Task GetAuthenticatedCustomer() return customer; } - private bool IsApiFrontAuthenticated() + private async Task IsApiFrontAuthenticated() { - var endpoint = _httpContextAccessor.HttpContext.GetEndpoint(); - if (endpoint == null) return false; - - var authorizeAttributes = endpoint.Metadata.GetOrderedMetadata(); - return authorizeAttributes.Any(attr => attr.AuthenticationSchemes?.Contains(FrontendAPIConfig.AuthenticationScheme) == true); + var authResult = await _httpContextAccessor.HttpContext.AuthenticateAsync(FrontendAPIConfig.AuthenticationScheme); + return authResult.Succeeded; }