@@ -212,7 +212,11 @@ public async Task<ActionResult> Exchange()
212
212
// Create a new authentication ticket, but reuse the properties stored in the
213
213
// authorization code/refresh token, including the scopes originally granted.
214
214
var ticket = await CreateTicketAsync ( user , context ) ;
215
- ticket . Principal . SetAuthenticationMethod ( info . Principal . GetAuthenticationMethod ( ) , [ Destinations . AccessToken ] ) ;
215
+
216
+ var destinations = new [ ] { Destinations . AccessToken } ;
217
+ CopyClaim ( info . Principal , ticket . Principal , ClaimTypes . AuthenticationMethod , destinations ) ;
218
+ CopyClaim ( info . Principal , ticket . Principal , PlatformConstants . Security . Claims . OperatorUserId , destinations ) ;
219
+ CopyClaim ( info . Principal , ticket . Principal , PlatformConstants . Security . Claims . OperatorUserName , destinations ) ;
216
220
217
221
return SignIn ( ticket . Principal , ticket . AuthenticationScheme ) ;
218
222
}
@@ -288,10 +292,8 @@ public async Task<ActionResult> Exchange()
288
292
}
289
293
290
294
// Resolve Impersonator from claims or from current user
291
- var operatorUserId = string . IsNullOrEmpty ( User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserId ) ) ?
292
- user . Id : User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserId ) ;
293
- var operatorUserName = string . IsNullOrEmpty ( User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserName ) ) ?
294
- user . UserName : User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserName ) ;
295
+ var operatorUserId = User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserId ) ? . EmptyToNull ( ) ?? user . Id ;
296
+ var operatorUserName = User . FindFirstValue ( PlatformConstants . Security . Claims . OperatorUserName ) ? . EmptyToNull ( ) ?? user . UserName ;
295
297
296
298
var userId = openIdConnectRequest . GetParameter ( "user_id" ) ? . Value ? . ToString ( ) ;
297
299
ApplicationUser impersonatedUser ;
@@ -567,6 +569,12 @@ public async Task<IActionResult> Logout()
567
569
}
568
570
569
571
572
+ private static void CopyClaim ( ClaimsPrincipal source , ClaimsPrincipal target , string claimType , IList < string > destinations )
573
+ {
574
+ var value = source . FindFirstValue ( claimType ) ;
575
+ target . SetClaimWithDestinations ( claimType , value , destinations ) ;
576
+ }
577
+
570
578
private static bool RequestHasExpired ( OpenIddictRequest request , AuthenticateResult result )
571
579
{
572
580
return request . MaxAge != null &&
0 commit comments