Activities of "pvala"

Hi Team, I tried one method to update the roles of the User in the Claims.

What I did is I added this class in my AuthServer

using G1.health.ClinicService.ClinicSetup; using G1.health.IdentityService.Users; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Options; using System.Security.Claims; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Security.Claims; using Volo.Abp.Uow;

namespace G1.health.AuthServer;

public class AbpUserClaimsPrincipalFactory : UserClaimsPrincipalFactory<Volo.Abp.Identity.IdentityUser, Volo.Abp.Identity.IdentityRole>, ITransientDependency { protected ICurrentPrincipalAccessor CurrentPrincipalAccessor { get; } protected IAbpClaimsPrincipalFactory AbpClaimsPrincipalFactory { get; } protected IdentityUserManager IdentityUserManager { get; }

public AbpUserClaimsPrincipalFactory(
    UserManager&lt;Volo.Abp.Identity.IdentityUser&gt; userManager,
    RoleManager&lt;Volo.Abp.Identity.IdentityRole&gt; roleManager,
    IOptions&lt;IdentityOptions&gt; options,
    ICurrentPrincipalAccessor currentPrincipalAccessor,
    IAbpClaimsPrincipalFactory abpClaimsPrincipalFactory,
    IdentityUserManager identityUserManager)
    : base(
        userManager,
        roleManager,
        options)
{
    CurrentPrincipalAccessor = currentPrincipalAccessor;
    AbpClaimsPrincipalFactory = abpClaimsPrincipalFactory;
    IdentityUserManager = identityUserManager;
}

[UnitOfWork]
protected override async Task&lt;ClaimsIdentity&gt; GenerateClaimsAsync(Volo.Abp.Identity.IdentityUser user)
{
    var id = await base.GenerateClaimsAsync(user).ConfigureAwait(false);
    if (UserManager.SupportsUserRole)
    {
    -- the next line is my code which I have written to fetch the roles for the user
        var roles = await IdentityUserManager.GetRoleNamesAsync(user).ConfigureAwait(false);
        foreach (var roleName in roles)
        {
            id.AddClaim(new Claim(Options.ClaimsIdentity.RoleClaimType, roleName));
            if (RoleManager.SupportsRoleClaims)
            {
                var role = await RoleManager.FindByNameAsync(roleName).ConfigureAwait(false);
                if (role != null)
                {
                    id.AddClaims(await RoleManager.GetClaimsAsync(role).ConfigureAwait(false));
                }
            }
        }
    }
    return id;
}

}

And added the pre-configuration of this class in my module.cs class of AuthServer:

public override void PreConfigureServices(ServiceConfigurationContext context)
{
--- other configuration ---

    PreConfigure&lt;IdentityBuilder&gt;(builder =>
    {
        builder.AddClaimsPrincipalFactory&lt;AbpUserClaimsPrincipalFactory&gt;();
    });
}

And I again checked the claims of the current user as you mentioned earlier and I got "admin" as a "role" claim for the user I am trying to log in with, but after clicking on the Login button, it would just stay on the same login page and it won't redirect to the angular app.

Any updates?

I have 2 tenants with which I am working, one is using the typical ABP Framework functionalities where I am not configuring anything for Roles and Users and another tenant where I am using the functionality for Roles and User which I mentioned earlier (custom tables for Roles and Users). I logged in with the admin users in both the tenants one by one and I took the bearer tokens from the API calls for both.

I then decoded both the tokens on jwt.io, and this is what I got :

Tenant without any configurations :

{ "iss": "https://testdev.localhost:44322/", "exp": 1726231353, "iat": 1726227753, "aud": [ "AccountService", "IdentityService", "AdministrationService", "SaasService", "ProductService", "ClinicService", "AppointmentService", "FormsService" ], "scope": "offline_access openid profile email phone AccountService IdentityService AdministrationService SaasService ProductService ClinicService AppointmentService FormsService", "jti": "66a31ba9-3f34-4b08-99eb-1af568b2f9aa", "sub": "3a104ca8-2d0b-0494-3653-5e7e48633bd5", "tenantid": "3a104ca8-1855-db3b-b3ff-111fbf324753", "session_id": "8f3fd4b7-af95-4010-84c6-ae1f3ee5c927", "unique_name": "admin", "oi_prst": "Angular", "oi_au_id": "3a104cb2-5231-d25e-fb31-c2164327d46f", "preferred_username": "admin", "given_name": "admin", "role": [ "viewProfile", "admin" ], "email": "admin@cureandcare.com", "email_verified": "False", "phone_number_verified": "False", "client_id": "Angular", "oi_tkn_id": "3a14fd5e-03f3-c2ee-dee4-f8748f5e4497" }

Tenant with my overridden configurations for Roles and Users :

{ "iss": "https://test2dev.localhost:44322/", "exp": 1726231274, "iat": 1726227674, "aud": [ "AccountService", "IdentityService", "AdministrationService", "SaasService", "ProductService", "ClinicService", "AppointmentService", "FormsService" ], "scope": "offline_access openid profile email phone AccountService IdentityService AdministrationService SaasService ProductService ClinicService AppointmentService FormsService", "jti": "cccb1c53-8fa5-499a-93c9-3f432a7af6a1", "sub": "3a0daa97-5fba-2079-563c-3e26309bdc81", "tenantid": "3a0daa97-5b6d-e661-4f00-22309be7478d", "session_id": "07e566b7-b6f9-4415-8c16-681606f245a4", "unique_name": "admin", "oi_prst": "Angular", "oi_au_id": "3a14ecaf-dae0-d535-4201-7197e6e3092e", "preferred_username": "admin", "given_name": "admin", "email": "safwan@gmail.com", "email_verified": "False", "phone_number_verified": "False", "client_id": "Angular", "oi_tkn_id": "3a14fd5c-cdc9-8b1a-c475-2c611fd52277" }

If you notice here, the token in which I did my configurations is missing the "roles" property, so conclusively, the roles aren't getting passed at first place when the JWT token creation is occurring. How do I deal with that? Where can I check what roles are being passed when the token is created?

I saved the Claims in a txt file, this is what I got :

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: iss ValueType: http://www.w3.org/2001/XMLSchema#string Value: https://test2dev.localhost:44322/ OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: exp ValueType: http://www.w3.org/2001/XMLSchema#integer64 Value: 1726205828 OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: iat ValueType: http://www.w3.org/2001/XMLSchema#integer64 Value: 1726202228 OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AccountService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: IdentityService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AdministrationService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: SaasService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: ProductService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: ClinicService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AppointmentService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: FormsService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: scope ValueType: http://www.w3.org/2001/XMLSchema#string Value: offline_access openid profile email phone AccountService IdentityService AdministrationService SaasService ProductService ClinicService AppointmentService FormsService OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: jti ValueType: http://www.w3.org/2001/XMLSchema#string Value: 97cbc847-f151-4a24-b637-898808040e38 OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: sub ValueType: http://www.w3.org/2001/XMLSchema#string Value: 3a0daa97-5fba-2079-563c-3e26309bdc81 OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: tenantid ValueType: http://www.w3.org/2001/XMLSchema#string Value: 3a0daa97-5b6d-e661-4f00-22309be7478d OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: session_id ValueType: http://www.w3.org/2001/XMLSchema#string Value: e37331a7-978c-43ea-ab51-a4a24587245f OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: unique_name ValueType: http://www.w3.org/2001/XMLSchema#string Value: admin OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: oi_prst ValueType: http://www.w3.org/2001/XMLSchema#string Value: Angular OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: oi_au_id ValueType: http://www.w3.org/2001/XMLSchema#string Value: 3a14ecaf-dae0-d535-4201-7197e6e3092e OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: preferred_username ValueType: http://www.w3.org/2001/XMLSchema#string Value: admin OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: given_name ValueType: http://www.w3.org/2001/XMLSchema#string Value: admin OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: email ValueType: http://www.w3.org/2001/XMLSchema#string Value: safwan@gmail.com OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: email_verified ValueType: http://www.w3.org/2001/XMLSchema#string Value: False OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: phone_number_verified ValueType: http://www.w3.org/2001/XMLSchema#string Value: False OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: client_id ValueType: http://www.w3.org/2001/XMLSchema#string Value: Angular OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: https://test2dev.localhost:44322/ Type: oi_tkn_id ValueType: http://www.w3.org/2001/XMLSchema#string Value: 3a14fbd8-86fd-8c6a-7c4a-471d72770d1f OriginalIssuer: https://test2dev.localhost:44322/ Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_tkn_typ ValueType: http://www.w3.org/2001/XMLSchema#string Value: access_token OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_crt_dt ValueType: http://www.w3.org/2001/XMLSchema#string Value: Fri, 13 Sep 2024 04:37:08 GMT OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_exp_dt ValueType: http://www.w3.org/2001/XMLSchema#string Value: Fri, 13 Sep 2024 05:37:08 GMT OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AccountService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: IdentityService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AdministrationService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: SaasService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: ProductService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: ClinicService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: AppointmentService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_aud ValueType: http://www.w3.org/2001/XMLSchema#string Value: FormsService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: offline_access OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: openid OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: profile OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: email OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: phone OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: AccountService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: IdentityService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: AdministrationService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: SaasService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: ProductService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: ClinicService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: AppointmentService OriginalIssuer: LOCAL AUTHORITY Properties:

Subject: System.Security.Claims.ClaimsIdentity Issuer: LOCAL AUTHORITY Type: oi_scp ValueType: http://www.w3.org/2001/XMLSchema#string Value: FormsService OriginalIssuer: LOCAL AUTHORITY Properties:

I added the RemoteService endpoints of the FormsService which is https://localhost:44395 in the appsettings.json file of the AuthServer (where I am trying to make the API call). And I changed the AddStaticHttpClientProxies to AddHttpClientProxies in the FormsServiceHttpApiClientModule.cs file. And it works fine.

But when I keep the AddStaticHttpClientProxies to use the static proxies, it throws the following error :

2024-08-12 13:02:59.777 +05:30 [ERR] An exception was thrown while activating λ:Volo.Abp.Http.Client.ClientProxying.IClientProxyApiDescriptionFinder -> Volo.Abp.Http.Client.ClientProxying.ClientProxyApiDescriptionFinder. Autofac.Core.DependencyResolutionException: An exception was thrown while activating λ:Volo.Abp.Http.Client.ClientProxying.IClientProxyApiDescriptionFinder -> Volo.Abp.Http.Client.ClientProxying.ClientProxyApiDescriptionFinder. ---> Autofac.Core.DependencyResolutionException: An exception was thrown while invoking the constructor 'Void .ctor(Volo.Abp.VirtualFileSystem.IVirtualFileProvider, Volo.Abp.Json.IJsonSerializer)' on type 'ClientProxyApiDescriptionFinder'. ---> System.NullReferenceException: Object reference not set to an instance of an object. at Volo.Abp.Http.Client.ClientProxying.ClientProxyApiDescriptionFinder.Initialize() at lambda_method80(Closure, Object[])

And I tried to check the code, and it turned out that it's coming from ClientProxyBase file from the Volo.Abp.Http.Client package (namespace : Volo.Abp.Http.Client.ClientProxying), here there's this propery named IClientProxyApiDescriptionFinder which is throwing the NullReferenceExceoption because of which it's not able to create the proxies.

protected virtual ClientProxyRequestContext BuildHttpProxyClientProxyContext(string methodName, ClientProxyRequestTypeValue? arguments = null)
{
    if (arguments == null)
    {
        arguments = new ClientProxyRequestTypeValue();
    }

    var methodUniqueName = $"{typeof(TService).FullName}.{methodName}.{string.Join("-", arguments.Values.Select(x => TypeHelper.GetFullNameHandlingNullableAndGenerics(x.Key)))}";
    var action = ClientProxyApiDescriptionFinder.FindAction(methodUniqueName);
    if (action == null)
    {
        throw new AbpException($"The API description of the {typeof(TService).FullName}.{methodName} method was not found!");
    }

    var actionArguments = action.Parameters.GroupBy(x => x.NameOnMethod).ToList();
    if (action.SupportedVersions != null && action.SupportedVersions.Any())
    {
        //TODO: make names configurable
        actionArguments.RemoveAll(x => x.Key == "api-version" || x.Key == "apiVersion");
    }

    return new ClientProxyRequestContext(
        action,
            actionArguments
            .Select((x, i) => new KeyValuePair&lt;string, object&gt;(x.Key, arguments.Values[i].Value))
            .ToDictionary(x => x.Key, x => x.Value),
        typeof(TService));
}

From this piece of code the problem seems to be coming, here in the code the line

var action = ClientProxyApiDescriptionFinder.FindAction(methodUniqueName);

the ClientProxyApiDescriptionFinder property of the class which is coming as null and hence the whole action is failing.

As you mentioned, the https://localhost:44325/api/abp/api-definition endpoint should return the list of all the endpoints. I checked this in the older version (7.3.2), there it was returning all the endpoints of the application, but in the upgraded version (8.2.1), when hitting the same endpoint, it only returned the following endpoints :

{ "modules": { "abp": {}, "auditLogging": {}, "featureManagement": {}, "fileManagement": {}, "gdpr": {}, "languageManagement": {}, "permissionManagement": {}, "settingManagement": {}, "textTemplateManagement": {} }, "types": {} }

(Because of the words limit I have removed the internal content of each module. The point here is that there is no endpoint in this JSON which corresponds to any of my microservices). This is happening in the newer version.

Can we set-up a meeting to resolve the issue?

My forms service is running on the port 44395, and when I hit the https://localhost:44395/api/abp/api-definition endpoint, all the API endpoints are there in the response, including the one that I am trying to use in the AuthServer.

Yes, I have added the FormsServiceHttpApiModule dependency in my WebGatewayModule.cs file, but when I hit the https://localhost:44325/api/abp/api-definition endpoint, it shows the endpoints of only the Administration service.

This is what we are getting on the Apache JMeter while performing the test :

Showing 21 to 30 of 77 entries
Made with ❤️ on ABP v9.0.0-preview Updated on September 19, 2024, 10:13