Skip to content

Commit f4c305e

Browse files
committed
feat: add IsImpresonated extension
1 parent c235fe7 commit f4c305e

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/VirtoCommerce.Platform.Security/Extensions/ClaimsPrincipalExtensions.cs

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Security.Claims;
44
using OpenIddict.Abstractions;
5+
using VirtoCommerce.Platform.Core;
56

67
namespace VirtoCommerce.Platform.Security.Extensions
78
{
@@ -42,5 +43,11 @@ public static ClaimsPrincipal SetClaimWithDestinations(this ClaimsPrincipal clai
4243

4344
return claimsPrincipal;
4445
}
46+
47+
public static bool IsImpersonated(this ClaimsPrincipal claimsPrincipal)
48+
{
49+
return claimsPrincipal?.HasClaim(PlatformConstants.Security.Claims.OperatorUserId) == true &&
50+
claimsPrincipal?.HasClaim(PlatformConstants.Security.Claims.OperatorUserName) == true;
51+
}
4552
}
4653
}

src/VirtoCommerce.Platform.Web/Controllers/Api/AuthorizationController.cs

+2
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ public async Task<ActionResult> Exchange()
335335
}
336336
}
337337

338+
await HandleTokenRequest(impersonatedUser, context);
339+
338340
// Create a new authentication ticket, but reuse the properties stored in the
339341
// authorization code/refresh token, including the scopes originally granted.
340342
var ticket = await CreateTicketAsync(impersonatedUser, context);

0 commit comments

Comments
 (0)