|
|
@ -1,5 +1,7 @@ |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
|
|
|
using System.Security.Principal; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using JetBrains.Annotations; |
|
|
using Microsoft.AspNetCore.Identity; |
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.Identity.AspNetCore; |
|
|
namespace Volo.Abp.Identity.AspNetCore; |
|
|
@ -17,8 +19,9 @@ public class AbpSecurityStampValidatorCallback |
|
|
/// This is needed to preserve claims such as idp, auth_time, amr.
|
|
|
/// This is needed to preserve claims such as idp, auth_time, amr.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="context">The context.</param>
|
|
|
/// <param name="context">The context.</param>
|
|
|
|
|
|
/// <param name="refreshingPrincipalOptions">The AbpRefreshingPrincipalOptions.</param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public static Task UpdatePrincipal(SecurityStampRefreshingPrincipalContext context) |
|
|
public static Task UpdatePrincipal(SecurityStampRefreshingPrincipalContext context, AbpRefreshingPrincipalOptions refreshingPrincipalOptions) |
|
|
{ |
|
|
{ |
|
|
var newClaimTypes = context.NewPrincipal.Claims.Select(x => x.Type).ToArray(); |
|
|
var newClaimTypes = context.NewPrincipal.Claims.Select(x => x.Type).ToArray(); |
|
|
var currentClaimsToKeep = context.CurrentPrincipal.Claims.Where(x => !newClaimTypes.Contains(x.Type)).ToArray(); |
|
|
var currentClaimsToKeep = context.CurrentPrincipal.Claims.Where(x => !newClaimTypes.Contains(x.Type)).ToArray(); |
|
|
@ -26,6 +29,18 @@ public class AbpSecurityStampValidatorCallback |
|
|
var id = context.NewPrincipal.Identities.First(); |
|
|
var id = context.NewPrincipal.Identities.First(); |
|
|
id.AddClaims(currentClaimsToKeep); |
|
|
id.AddClaims(currentClaimsToKeep); |
|
|
|
|
|
|
|
|
|
|
|
if (refreshingPrincipalOptions.CurrentPrincipalKeepClaimTypes.Any()) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var claimType in refreshingPrincipalOptions.CurrentPrincipalKeepClaimTypes) |
|
|
|
|
|
{ |
|
|
|
|
|
var sessionIdClaim = context.CurrentPrincipal.Claims.FirstOrDefault(x => x.Type == claimType); |
|
|
|
|
|
if (sessionIdClaim != null) |
|
|
|
|
|
{ |
|
|
|
|
|
id.AddOrReplace(sessionIdClaim); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return Task.CompletedTask; |
|
|
return Task.CompletedTask; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|