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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
add Antiforgery token
dkucia5d7c8333df08
diff --git a/src/API/Grand.Api/Controllers/TokenWebController.cs b/src/API/Grand.Api/Controllers/TokenWebController.csindex 0fc5c1c51..8cc40a190 100644--- a/src/API/Grand.Api/Controllers/TokenWebController.cs+++ b/src/API/Grand.Api/Controllers/TokenWebController.cs@@ -6,6 +6,7 @@ using Grand.Business.Customers.Interfaces;using Grand.Domain.Customers;using Grand.Infrastructure;using MediatR;+using Microsoft.AspNetCore.Antiforgery;using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using System;@@ -23,6 +24,7 @@ namespace Grand.Api.Controllersprivate readonly IStoreHelper _storeHelper;private readonly IRefreshTokenService _refreshTokenService;private readonly IUserFieldService _userFieldService;+ private readonly IAntiforgery _antiforgery;public TokenWebController(ICustomerService customerService,@@ -30,7 +32,8 @@ namespace Grand.Api.ControllersIMediator mediator,IStoreHelper storeHelper,IRefreshTokenService refreshTokenService,- IUserFieldService userFieldService)+ IUserFieldService userFieldService,+ IAntiforgery antiforgery){_customerService = customerService;_customerManagerService = customerManagerService;@@ -38,6 +41,7 @@ namespace Grand.Api.Controllers_storeHelper = storeHelper;_refreshTokenService = refreshTokenService;_userFieldService = userFieldService;+ _antiforgery = antiforgery;}[AllowAnonymous]@@ -112,6 +116,13 @@ namespace Grand.Api.Controllersreturn Ok(token);}+ [HttpGet]+ public IActionResult Antiforgery()+ {+ var token = _antiforgery.GetAndStoreTokens(this.HttpContext).RequestToken;+ return Ok(token);+ }+private async Task<TokenDto> GetToken(Dictionary<string, string> claims, Customer customer){var token = await _mediator.Send(new GenerateTokenWebCommand() { Claims = claims });