Skip to content

Commit

Permalink
VCST-2048: Use ClaimsPrincipalExtensions GetUserId (#90)
Browse files Browse the repository at this point in the history
feat: Replace custom code with ClaimsPrincipalExtensions that resolves user id and name from IdentityOptions settings.
  • Loading branch information
OlegoO authored Nov 1, 2024
1 parent dfc56b0 commit 70eed8a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -41,7 +40,7 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext

using var userManager = _userManagerFactory();

var currentUserId = GetUserId(context);
var currentUserId = GetCurrentUserId(context);
var currentMember = await GetCustomerAsync(currentUserId, userManager);
var currentContact = currentMember as Contact;

Expand Down Expand Up @@ -185,10 +184,9 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
}
}

private static string GetUserId(AuthorizationHandlerContext context)
private static string GetCurrentUserId(AuthorizationHandlerContext context)
{
//PT-5375 use ClaimTypes instead of "name"
return context.User.FindFirstValue("name");
return context.User.GetUserId();
}

private async Task<bool> HasSameOrganizationAsync(Contact currentContact, string contactId, UserManager<ApplicationUser> userManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.Xapi.Core" Version="3.809.0" />
<PackageReference Include="VirtoCommerce.XOrder.Core" Version="3.806.0" />
<PackageReference Include="VirtoCommerce.Platform.Security" Version="3.853.0" />
<PackageReference Include="VirtoCommerce.Platform.Security" Version="3.861.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.817.0" />
<PackageReference Include="VirtoCommerce.MarketingModule.Core" Version="3.812.0" />
<PackageReference Include="VirtoCommerce.NotificationsModule.Core" Version="3.809.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<version>3.818.0</version>
<version-tag />

<platformVersion>3.853.0</platformVersion>
<platformVersion>3.861.0</platformVersion>
<dependencies>
<dependency id="VirtoCommerce.Core" version="3.808.0" />
<dependency id="VirtoCommerce.Customer" version="3.817.0" />
Expand Down

0 comments on commit 70eed8a

Please sign in to comment.