0
gvnuysal created
- ABP Framework version: v4.3.3
- UI type: Angular
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): no
Hi support, when we assign a new role to the user, we could not gain the properties of this role without logging out and logging in When we do F5 it doesn't work either.
We kept the user's token duration long.
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
8 Answer(s)
-
0
Hi,
We plan to introduce dynamic claims to solve the problem, see https://github.com/abpframework/abp/pull/8676
For now, you can refer this: https://support.abp.io/QA/Questions/2090/How-to-clear-cache-for-features
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Thanks @liangshiwei. But problem not solved. https://support.abp.io/QA/Questions/2090/How-to-clear-cache-for-features#answer-f36c97e0-8c78-c2ca-8362-3a000f923d93
I tried the middleware in the link above
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
Try
public static class RefreshRolesMiddlewareExtension { public static IApplicationBuilder UseRefreshRolesMiddleware(this IApplicationBuilder app) { return app.Use(async (ctx, next) => { var currentUser = ctx.RequestServices.GetRequiredService<ICurrentUser>(); if (!currentUser.IsAuthenticated) { await next(); return; } var userManager = ctx.RequestServices.GetRequiredService<IdentityUserManager>(); var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>(); var user = await userManager.GetByIdAsync(currentUser.GetId()); var roles= await userManager.GetRolesAsync(user); var claims = currentPrincipalAccessor.Principal.Claims.ToList(); claims.RemoveAll(x => x.Type == AbpClaimTypes.Role); claims.AddRange(roles.Select(x=> new Claim(AbpClaimTypes.Role, x))); using (currentPrincipalAccessor.Change(claims)) { await next(); } }); } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi,
Please try:
public static class RefreshRolesMiddlewareExtension { public static IApplicationBuilder UseRefreshRolesMiddleware(this IApplicationBuilder app) { return app.Use(async (ctx, next) => { var currentUser = ctx.RequestServices.GetRequiredService<ICurrentUser>(); if (!currentUser.IsAuthenticated) { await next(); return; } var userManager = ctx.RequestServices.GetRequiredService<IdentityUserManager>(); var currentPrincipalAccessor = ctx.RequestServices.GetRequiredService<ICurrentPrincipalAccessor>(); var user = await userManager.GetByIdAsync(currentUser.GetId()); var roles= await userManager.GetRolesAsync(user); currentPrincipalAccessor.Principal.Identities.First().AddClaims(roles.Select(x=> new Claim(AbpClaimTypes.Role, x))); await next(); }); } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)



