Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-2048: Use ClaimsPrincipalExtensions GetUserId #16

Merged
merged 7 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Security.Claims;
using VirtoCommerce.Platform.Core.Security;
using static VirtoCommerce.Xapi.Core.ModuleConstants;

namespace VirtoCommerce.Xapi.Core.Extensions;
Expand All @@ -7,6 +8,6 @@ public static class ClaimsPrincipalExtensions
{
public static string GetCurrentUserId(this ClaimsPrincipal claimsPrincipal)
{
return claimsPrincipal?.FindFirstValue(ClaimTypes.NameIdentifier) ?? claimsPrincipal?.FindFirstValue("name") ?? AnonymousUser.UserName;
return claimsPrincipal?.GetUserId() ?? AnonymousUser.UserName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class ResolveEventStreamContextExtensions
public static string GetCurrentUserId(this IResolveEventStreamContext resolveContext)
{
var claimsPrincipal = GetCurrentPrincipal(resolveContext);
return claimsPrincipal?.FindFirstValue(ClaimTypes.NameIdentifier) ?? claimsPrincipal?.FindFirstValue("name") ?? ModuleConstants.AnonymousUser.UserName;
return claimsPrincipal?.GetCurrentUserId();
}

public static ClaimsPrincipal GetCurrentPrincipal(this IResolveEventStreamContext resolveContext)
Expand Down
1 change: 1 addition & 0 deletions src/VirtoCommerce.Xapi.Core/VirtoCommerce.Xapi.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<PackageReference Include="GraphQL.Server.Transports.AspNetCore.NewtonsoftJson" Version="5.0.2" />
<PackageReference Include="PipelineNet" Version="0.9.0" />
<PackageReference Include="RedLock.net" Version="2.3.2" />
<PackageReference Include="VirtoCommerce.Platform.Core" Version="3.861.0-alpha.12998-vcst-2048" />
<PackageReference Include="VirtoCommerce.CoreModule.Core" Version="3.808.0" />
<PackageReference Include="VirtoCommerce.CustomerModule.Core" Version="3.817.0" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.804.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/VirtoCommerce.Xapi.Data/Services/UserManagerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Task CheckUserState(string userId, bool allowAnonymous)
public Task CheckCurrentUserState(IResolveFieldContext context, bool allowAnonymous)
{
var principal = context.GetCurrentPrincipal();
var userId = principal.GetCurrentUserId();
var userId = principal?.GetCurrentUserId();
var isExternalSignIn = principal.IsExternalSignIn();

return CheckUserState(userId, allowAnonymous, isExternalSignIn);
Expand Down
Loading