File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
modules/identity/src/Volo.Abp.Identity.AspNetCore/Volo/Abp/Identity/AspNetCore Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System . Linq ;
2
+ using System . Threading . Tasks ;
3
+ using Microsoft . AspNetCore . Identity ;
4
+
5
+ namespace Volo . Abp . Identity . AspNetCore
6
+ {
7
+ public class AbpSecurityStampValidatorCallback
8
+ {
9
+ /// <summary>
10
+ /// Implements callback for SecurityStampValidator's OnRefreshingPrincipal event.
11
+ /// https://github.com/IdentityServer/IdentityServer4/blob/main/src/AspNetIdentity/src/SecurityStampValidatorCallback.cs
12
+ /// </summary>
13
+ public class SecurityStampValidatorCallback
14
+ {
15
+ /// <summary>
16
+ /// Maintains the claims captured at login time that are not being created by ASP.NET Identity.
17
+ /// This is needed to preserve claims such as idp, auth_time, amr.
18
+ /// </summary>
19
+ /// <param name="context">The context.</param>
20
+ /// <returns></returns>
21
+ public static Task UpdatePrincipal ( SecurityStampRefreshingPrincipalContext context )
22
+ {
23
+ var newClaimTypes = context . NewPrincipal . Claims . Select ( x => x . Type ) . ToArray ( ) ;
24
+ var currentClaimsToKeep = context . CurrentPrincipal . Claims . Where ( x => ! newClaimTypes . Contains ( x . Type ) ) . ToArray ( ) ;
25
+
26
+ var id = context . NewPrincipal . Identities . First ( ) ;
27
+ id . AddClaims ( currentClaimsToKeep ) ;
28
+
29
+ return Task . CompletedTask ;
30
+ }
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments