Open Closed

Dynamic claims not working in microservice solution #9226


User avatar
0
aziz.bouhejba created

Hello, we noticed that when demote/change the role of someone, it doesn't get reflected instantly. we figured it's because caching. but we thought UseDynamicClaims covered that case.

We don't want an admin that we demote to a simple guest to still have admin powers for an hour and thought it should be working out of the box.

This is issue is noticeable in our blazor app and our maui blazor hybrid mobile app.

We tried adding a middleware in identity service to replace the claims by the current role claims but it didn't work.

Do you have any suggestions?


11 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you test this in a new microservice solution?

    If it still not working, Please share your steps.

    Thanks.

  • User Avatar
    0
    aziz.bouhejba created

    yes done that, same issue

    Reproduction Steps:

    1. Create a new microservice solution.
    2. Create a new tenant.
    3. Log in as the tenant admin.
    4. Create a new role called "Guest".
    5. Create a user named "TestUser" and assign the "Admin" role.
    6. Open an incognito browser and log in as TestUser.
    7. Confirm that TestUser has admin privileges — ✅ expected.
    8. Log out TestUser.
    9. As admin, modify TestUser’s role to "Guest" (remove admin role).
    10. Log in again as TestUser (in incognito).
    11. TestUser still has admin privileges — ❌ unexpected.

    Expected Behavior:

    After logging out and back in, TestUser should have Guest permissions only, with admin privileges revoked. According to the ABP documentation, role changes should take effect at the next request or at least after reauthentication. For us it doesn't even work with a logout/login

    Actual Behavior:

    Role changes are not applied even after logout/login. It seems role claims are cached or not refreshed properly.

    Only solution we found right now is creating a redis cache service and deleting user cache (not ideal)..

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I will check your steps. Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you try to depend on AbpIdentityProEntityFrameworkCoreModule in AdministrationService?

  • User Avatar
    0
    aziz.bouhejba created

    yes it works.. thank you. I guess it's a template issue then?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Yes, I will update the template code.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Instead of adding AbpIdentityProEntityFrameworkCoreModule in AdministrationService

    Can you try to configure the WebRemoteDynamicClaimsPrincipalContributorOptions in AdministrationService?

    Thanks.

    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<WebRemoteDynamicClaimsPrincipalContributorOptions>(options =>
        {
            options.IsEnabled = true;
        });
    }
    

    Also please depends on the typeof(AbpAspNetCoreAuthenticationJwtBearerModule) in AdministrationService .

  • User Avatar
    0
    aziz.bouhejba created

    Hi!

    tried the new proposed solution, doesn't work on our Blazor Web app. both proposed solutions also don't work for our MAUI Blazor hybrid mobile app.

    We need the dynamic claims to also work on mobile app.

    Thank you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Have you added the AbpAspNetCoreAuthenticationJwtBearerModule in AdministrationService?

  • User Avatar
    0
    aziz.bouhejba created

    yes I did

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    But I couldn't reproduce the problem in a new microservice template after configuring WebRemoteDynamicClaimsPrincipalContributorOptions.

    The dynamic claims works.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.3.0-preview. Updated on May 12, 2025, 05:22