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-2464: Fix refresh token after impersonation #2869

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Changes from 1 commit
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
Expand Up @@ -212,7 +212,11 @@ public async Task<ActionResult> Exchange()
// Create a new authentication ticket, but reuse the properties stored in the
// authorization code/refresh token, including the scopes originally granted.
var ticket = await CreateTicketAsync(user, context);
ticket.Principal.SetAuthenticationMethod(info.Principal.GetAuthenticationMethod(), [Destinations.AccessToken]);

var destinations = new[] { Destinations.AccessToken };
CopyClaim(info.Principal, ticket.Principal, ClaimTypes.AuthenticationMethod, destinations);
CopyClaim(info.Principal, ticket.Principal, PlatformConstants.Security.Claims.OperatorUserId, destinations);
CopyClaim(info.Principal, ticket.Principal, PlatformConstants.Security.Claims.OperatorUserName, destinations);

return SignIn(ticket.Principal, ticket.AuthenticationScheme);
}
Expand Down Expand Up @@ -288,10 +292,8 @@ public async Task<ActionResult> Exchange()
}

// Resolve Impersonator from claims or from current user
var operatorUserId = string.IsNullOrEmpty(User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserId)) ?
user.Id : User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserId);
var operatorUserName = string.IsNullOrEmpty(User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserName)) ?
user.UserName : User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserName);
var operatorUserId = User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserId)?.EmptyToNull() ?? user.Id;
var operatorUserName = User.FindFirstValue(PlatformConstants.Security.Claims.OperatorUserName)?.EmptyToNull() ?? user.UserName;

var userId = openIdConnectRequest.GetParameter("user_id")?.Value?.ToString();
ApplicationUser impersonatedUser;
Expand Down Expand Up @@ -567,6 +569,12 @@ public async Task<IActionResult> Logout()
}


private static void CopyClaim(ClaimsPrincipal source, ClaimsPrincipal target, string claimType, IList<string> destinations)
{
var value = source.FindFirstValue(claimType);
target.SetClaimWithDestinations(claimType, value, destinations);
}

private static bool RequestHasExpired(OpenIddictRequest request, AuthenticateResult result)
{
return request.MaxAge != null &&
Expand Down
Loading