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.
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
-
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
-
0
-
0
Hi @liangshiwei,
It would be nice if you could share an example.
-
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(); } }); } }
-
0
Thanks @liangshiwei.
-
0
-
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(); }); } }