Open Closed

Unable to access Identity Microservice api's with tenant in token #9178


User avatar
0
rogercprops created
  • Exception message and full stack trace: 4/21/2025 8:31:05 PM [Information] Request starting "HTTP/1.1" "GET" "http"://"localhost:44378""""/api/identity/users""" - null null 4/21/2025 8:31:05 PM [Debug] Get dynamic claims cache for tenant: 6271b9cb-31a4-07e1-e895-3a18325419b0 4/21/2025 8:31:05 PM [Debug] Get dynamic claims cache for user: b7a3c0e6-0b62-1904-314a-3a196bd42430 4/21/2025 8:31:05 PM [Debug] SessionId(4803aa26-2539-4cc7-a833-b5c08567966e) found in cache, Updating hit count(2), last access time(4/21/2025 3:31:05 PM) and IP address(::1). 4/21/2025 8:31:05 PM [Information] Executing endpoint '"Volo.Abp.Identity.IdentityUserController.GetListAsync (Volo.Abp.Identity.Pro.HttpApi)"' 4/21/2025 8:31:05 PM [Information] Route matched with "{area = "identity", controller = "User", action = "GetList"}". Executing controller action with signature "System.Threading.Tasks.Task1[Volo.Abp.Application.Dtos.PagedResultDto1[Volo.Abp.Identity.IdentityUserDto]] GetListAsync(Volo.Abp.Identity.GetIdentityUsersInput)" on controller "Volo.Abp.Identity.IdentityUserController" ("Volo.Abp.Identity.Pro.HttpApi"). 4/21/2025 8:31:05 PM [Debug] PermissionStore.GetCacheItemAsync: pn:U,pk:b7a3c0e6-0b62-1904-314a-3a196bd42430,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Debug] Found in the cache: pn:U,pk:b7a3c0e6-0b62-1904-314a-3a196bd42430,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Debug] PermissionStore.GetCacheItemAsync: pn:R,pk:identitytest,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Debug] Found in the cache: pn:R,pk:identitytest,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Debug] PermissionStore.GetCacheItemAsync: pn:C,pk:CloverleafApi,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Debug] Found in the cache: pn:C,pk:CloverleafApi,n:AbpIdentity.Users 4/21/2025 8:31:05 PM [Information] Authorization failed. "These requirements were not met: PermissionRequirement: AbpIdentity.Users" 4/21/2025 8:31:05 PM [Warning] ---------- RemoteServiceErrorInfo ---------- { "code": "Volo.Authorization:010001", "message": "Authorization failed! Given policy has not granted.", "details": null, "data": null, "validationErrors": null } 4/21/2025 8:31:05 PM [Warning] Volo.Abp.Authorization.AbpAuthorizationException: Exception of type 'Volo.Abp.Authorization.AbpAuthorizationException' was thrown. at Microsoft.AspNetCore.Authorization.AbpAuthorizationServiceExtensions.CheckAsync(IAuthorizationService authorizationService, AuthorizationPolicy policy) at Volo.Abp.Authorization.MethodInvocationAuthorizationService.CheckAsync(MethodInvocationAuthorizationContext context) at Volo.Abp.Authorization.AuthorizationInterceptor.AuthorizeAsync(IAbpMethodInvocation invocation) at Volo.Abp.Authorization.AuthorizationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Validation.ValidationInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Auditing.AuditingInterceptor.ProceedByLoggingAsync(IAbpMethodInvocation invocation, AbpAuditingOptions options, IAuditingHelper auditingHelper, IAuditLogScope auditLogScope) at Volo.Abp.Auditing.AuditingInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at Castle.DynamicProxy.AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) at Volo.Abp.Castle.DynamicProxy.CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() at Volo.Abp.Uow.UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) at Volo.Abp.Castle.DynamicProxy.CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) at lambda_method5120(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) 4/21/2025 8:31:05 PM [Warning] Code:Volo.Authorization:010001 4/21/2025 8:31:05 PM [Information] AuthenticationScheme: "Bearer" was forbidden.

  • Steps to reproduce the issue:

    • Create a microservice solution using Abp Studio

    • Create a user with admin role assigned in SaaS tenant

    • Get a token for the user in a SaaS tenant This the decoded JwT { "header": { "alg": "RS256", "kid": "", "x5t": "", "typ": "at+jwt" }, "payload": { "iss": "http://localhost:44311/", "aud": [ "AuthServer", "IdentityService", "ServicesService", "SaasService", "AuditLoggingService", "GdprService", "LanguageService" ], "scope": "AdministrationService AuditLoggingService AuthServer ClientService GdprService IdentityService LanguageService SaasService", "jti": "", "sub": "", "preferred_username": "testuser", "email": "", "role": "admin", "tenantid": "6271b9cb-31a4-07e1-e895-3a18325419b0", "given_name": "", "family_name": "", "phone_number_verified": "False", "email_verified": "False", "session_id": "", "unique_name": "", "oi_prst": "", "client_id": "", "oi_tkn_id": "" } }

    • Use Postman to call any identity service api with the token. For example GET api/idenity/users

    • Call returns a 403 Forbidden error

    • Create a user with admin role assigned in host tenant

    • Get a token for a user in the host

This is the decoded JwT (note: no tenantid) { "header": { "alg": "RS256", "kid": "", "x5t": "", "typ": "at+jwt" }, "payload": { "iss": "http://localhost:44311/", "aud": [ "AuthServer", "IdentityService", "ServicesService", "SaasService", "AuditLoggingService", "GdprService", "LanguageService" ], "scope": "AdministrationService AuditLoggingService AuthServer ClientService GdprService IdentityService LanguageService SaasService", "jti": "", "sub": "", "preferred_username": "testadmin", "email": "", "role": "admin", "given_name": "", "family_name": "", "phone_number_verified": "False", "email_verified": "False", "session_id": "", "unique_name": "", "oi_prst": "", "client_id": "", "oi_tkn_id": "" } }

* Call the same identity api (GET api/idenity/users)
* Response returns the users in the host tenant

Here is the output from the Sql query on the Identity database SELECT * from [CloverleafCMSv2_Administration].[dbo].[AbpPermissionGrants] -- where (tenantId = 'dcb36c08-67ab-fa76-77dd-3a167cb44820' or tenantId = 'a3e9728b-d264-c114-b53c-3a13ab178ad2') where tenantId = '6271b9cb-31a4-07e1-e895-3a18325419b0' -- and ProviderName='R' and ProviderKey = 'admin' and Name like '%users%' order by tenantid, ProviderKey, Name

[ { "Id": "77a456bf-0e82-9808-104a-3a1832542987", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "0cfb4925-ce70-cabd-fa68-3a1832542989", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Create", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "f35e6343-104d-f03e-9d37-3a183254298d", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Delete", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "fdaf8b58-fcef-6eab-25c5-3a1832542993", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Export", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "e183ace3-8b4c-2cec-3446-3a1832542991", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Impersonation", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "38450b83-4e1e-1772-d0ce-3a1832542992", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Import", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "39fe41c3-daf4-cf05-a2a8-3a183254298f", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.ManagePermissions", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "032aaafe-0dce-42c9-4a04-3a183254298a", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Update", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "c1894400-a3b2-826e-0937-3a183254298c", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Update.ManageOU", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "5e5f7716-49ee-a8e9-06eb-3a183254298b", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.Update.ManageRoles", "ProviderName": "R", "ProviderKey": "admin" }, { "Id": "4fcd8817-8f4f-0d7b-dea3-3a1832542995", "TenantId": "6271b9cb-31a4-07e1-e895-3a18325419b0", "Name": "AbpIdentity.Users.ViewDetails", "ProviderName": "R", "ProviderKey": "admin" } ]


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

    hi

    Get a token for the user in a SaaS tenant

    How did you get the new token?

    Please share your HTTP request

    Thanks..

  • User Avatar
    0
    rogercprops created

    We developed an API that gets the token from the authserver using Duende.IdentityModel 7.0.0 ` public async Task

        var apiEndpoint = _configuration.GetValue<string>("AuthServiceBaseUrl");
        var scope = string.Join(" ", scopes);
        var discoveryCache = new DiscoveryCache(apiEndpoint);
        var disco = await discoveryCache.GetAsync();
    
        if (disco.IsError)
        {
            Console.WriteLine(disco.Error);
            throw new UserFriendlyException($"Error retrieving discovery document: {disco.Error}");
        }
    
        var client = new HttpClient();
    
        var passwordTokenRequest = new PasswordTokenRequest
        {
            Address = disco.TokenEndpoint,
            ClientId = clientId,
            ClientSecret = clientSecret,
            UserName = userName,
            Password = password,
            Scope = scope
        };
    
        if (Tenant != null) passwordTokenRequest.Headers.Add("tenant", Tenant);
        var tokenResponse = await client.RequestPasswordTokenAsync(passwordTokenRequest);
    
        TokenResponseDto tokenRequestResponse = new();
    
        if (tokenResponse.IsError)
        {
            Console.WriteLine("error", tokenResponse);
            throw new UserFriendlyException($"Error retrieving token: {tokenResponse.ErrorDescription}");
        }
        else
        {
            tokenRequestResponse.AccessToken = tokenResponse.AccessToken;
            tokenRequestResponse.RefreshToken = tokenResponse.RefreshToken;
            tokenRequestResponse.ExpiresIn = tokenResponse.ExpiresIn;
        }
    
        return tokenRequestResponse;
    }
    

    `

    Here's the curl request to get the token: ` curl --location 'http://localhost:44326/api/token'
    --header 'X-Forwarded-For: 192.0.2.172'
    --header 'Content-Type: application/json'
    --header 'Cookie: .AspNetCore.Culture=c%3Den%7Cuic%3Den'
    --data-raw '{ "tenant": "homefree",

    "clientId": "CloverleafApi",
    "clientSecret": "Fgf@E98M6XZs3w",
    "userName": "testadmin",
    "password": "Lucky7E!",
    "scopes": ["AdministrationService","AuditLoggingService","AuthServer","ClientService","GdprService","IdentityService", "LanguageService","SaasService","ServicesService", "CommunicationsTemplateService","MemberConfigService","ClientServicesQuery","FinancialService","ContactService","StaffService", "HousingService","EngagementLogService", "DocumentService", "NoteService"]
    

    }'`

    Here's the curl request to get the users (the authorization bearer is from the token response: curl --location 'http://localhost:44326/api/identity/users' \ --header 'Authorization: Bearer **** \ --header 'Cookie: .AspNetCore.Culture=c%3Den%7Cuic%3Den'

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please add profile roles email phone to your scopes

    "scopes": [
       "AdministrationService",
       "AuditLoggingService",
       "AuthServer",
       "ClientService",
       "GdprService",
       "IdentityService",
       "LanguageService",
       "SaasService",
       "ServicesService",
       "CommunicationsTemplateService",
       "MemberConfigService",
       "ClientServicesQuery",
       "FinancialService",
       "ContactService",
       "StaffService",
       "HousingService",
       "EngagementLogService",
       "DocumentService",
       "NoteService"
    ]
    
  • User Avatar
    0
    rogercprops created

    Same error.

    Here's the decoded token with the updated scopes

    { "header": { "alg": "RS256", "kid": "******", "x5t": "******", "typ": "at+jwt" }, "payload": { "iss": "http://localhost:44311/", "exp": 1745502008, "iat": 1745498408, "aud": [ "AuthServer", "IdentityService", "AdministrationService", "ServicesService", "SaasService", "AuditLoggingService", "GdprService", "LanguageService", "ClientService", "CommunicationsTemplateService", "ClientServicesQuery", "ContactService", "StaffService", "MemberConfigService", "FinancialService", "HousingService", "EngagementLogService", "DocumentService", "NoteService" ], "scope": "roles phone email profile address AdministrationService AuditLoggingService AuthServer ClientService GdprService IdentityService LanguageService SaasService ServicesService CommunicationsTemplateService MemberConfigService ClientServicesQuery FinancialService ContactService StaffService HousingService EngagementLogService DocumentService NoteService", "jti": "******", "sub": "******", "preferred_username": "testuser", "email": "******", "role": "admin", "tenantid": "6271b9cb-31a4-07e1-e895-3a18325419b0", "given_name": "******", "family_name":"******", "phone_number_verified": "False", "email_verified": "False", "session_id": "******", "unique_name": "******", "oi_prst": "CloverleafApi", "client_id": "CloverleafApi", "oi_tkn_id": "******" } }

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you set a breakpoint to check the current user claims?

    The access token seems no problem

    Thanks.

  • User Avatar
    0
    rogercprops created

    I'm not sure what you mean by checking the user claims. In the admin console I went to Claims for the user in the host & the user in the tenant and there were none.

    Again, I don't get the authorization error when I get a token for a user in the host tenant and of course it only returns users where TenantId is null.

    Here's the host token decoded: { "header": { "alg": "RS256", "kid": "", "x5t": "", "typ": "at+jwt" }, "payload": { "iss": "http://localhost:44311/", "exp": 1745505879, "iat": 1745502279, "aud": [ "AuthServer", "IdentityService", "AdministrationService", "ServicesService", "SaasService", "AuditLoggingService", "GdprService", "LanguageService", "ClientService", "CommunicationsTemplateService", "ClientServicesQuery", "ContactService", "StaffService", "MemberConfigService", "FinancialService", "HousingService", "EngagementLogService", "DocumentService", "NoteService" ], "scope": "roles phone email profile address AdministrationService AuditLoggingService AuthServer ClientService GdprService IdentityService LanguageService SaasService ServicesService CommunicationsTemplateService MemberConfigService ClientServicesQuery FinancialService ContactService StaffService HousingService EngagementLogService DocumentService NoteService", "jti": "c679b9ed-83dd-4f49-867a-4606cd822dd4", "sub": "3503fbd8-b3bb-e0de-d82f-3a18407a620a", "preferred_username": "cpradmin", "email": "", "role": "admin", "given_name": "", "family_name": "", "phone_number_verified": "False", "email_verified": "False", "session_id": "", "unique_name": "cpradmin", "oi_prst": "CloverleafApi", "client_id": "CloverleafApi", "oi_tkn_id": "******" } }

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share a test project and steps?

    I will download and debug it.

    liming.ma@volosoft.com

    Thanks

  • User Avatar
    0
    rogercprops created

    Hi,

    In attempting to build you a small test project to replicate our issue, I built a new micro service solution with ABP Studio but elected to use Abp 9.1 (our current solution is 9.0.4).

    I tried to replicate the error with the new solution but able to get a token for a tenant user then get users from api/identity/users without error. That tells me that the error was corrected in either 9.1 or in the micro-service templates.

    So I tried to upgrade our Abp packages by first upgrading to the latest version of the ABP CLI. Then I tried to use the ABP Studio, then Abp Suite, then using the ABP CLI from a terminal to upgrade our IdentityService. These only updated the application service project file <PackageReference Include="Volo.Abp.Studio.Client.AspNetCore" Version="0.9.23" /> to <PackageReference Include="Volo.Abp.Studio.Client.AspNetCore" Version="0.9.25" />

    None of the other packages were updated. I think this must be a bug in the latest version of ABP CLI/ABP Studio.

    In the end, I replaced all of the solutions from the Abp micro-service template with the ones generated I created with 9.1.

    You should note that the only change we made to any of the Abp template solutions was to the Auth server CloverleafCMSAuthServerModule. We added this to support getting a token for multi-tenancy to our 9.0.4 version, which I also added to the version created with 9.1. private void ConfigureMultiTenancy() { Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = true; }); }

    So, without going through the differences between the latest micro-service templates and the ones we created with ABP Studio back in February, I don't know if you all fixed the issue in the 9.1 packages or the micro-service templates.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I think this is a claim-type problem.

    The claim type and value in your access token don't match the API website.

    https://abp.io/community/articles/how-claim-type-works-in-asp-net-core-and-abp-framework-km5dw6g1

    Thanks.

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