Open Closed

Unable to use IIdentityRoleAppService in SampleAppService for module template #4844


User avatar
0
uyarbtrlp created
  • ABP Framework version: v5.3.3
  • UI type: MVC
  • DB provider: EF Core
  • Module Template (Separated Deployment & Databases Scenario): yes

Hello all,

I've wanted to use IIdentityRoleAppService to add roles, get roles etc. in my app service but somehow I have not been able to use it. I've examined the https://support.abp.io/QA/Questions/2785/Consume-external-REST-API-to-get-data issue to see how to use different application services in the app service. I've followed three steps that mentioned. I've ended up with "unauthorized error" even though I've had the right permissions. Here are the steps to reproduce the issue:

  1. Create a new solution by using the command abp new TestAppForRoleAppService -t module-pro --add-to-solution-file --output-folder C:\Users\TestAppForRoleAppService --version 5.3.3
  2. Create the db and seed the users
  3. Insert the Volo.Abp.Identity.Pro.Application.Contracts 5.3.3 package in TestAppForRoleAppService.Application.Contracts to get the interfaces.
  4. Insert the Volo.Abp.Identity.Pro.HttpApi.Client package in TestAppForRoleAppService.HttpApi.Host and insert it in module dependencies
  5. Remote service configuration on TestAppForRoleAppService.HttpApi.Host . (It's base url is https://localhost:44388/ which is the identity server url since the related services are in identity server)
  6. Use the IIdentityRoleAppServices to get all roles in the sample services
  7. Run the projects : TestAppForRoleAppService.HttpApiHost, TestAppForRoleAppService.IdentityServer and TestAppForRoleAppService.Web.Host
  8. Call it from the host by using the swagger and get the unauthorized error
  9. Check the identity server logs and see the error which is caused for missing privilege, but I have the right permission to get the roles.

Am I missing something to use the app service in another app service or is it kind a bug for the module template?

Thanks. Kind Regards


5 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can check this: https://github.com/abpframework/abp/blob/rel-5.2/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/ClientDemoService.cs#L39

    https://github.com/abpframework/abp/blob/rel-5.2/templates/module/aspnet-core/test/MyCompanyName.MyProjectName.HttpApi.Client.ConsoleTestApp/appsettings.json#L10

  • User Avatar
    0
    uyarbtrlp created

    Yes, I know how to use this in another client, but I want to use this app service with current user authorization in another web application. I don't want to configure the username or password on configuration file. How to use this app service without giving some information on configuration file? I prefer to do that with Dynamic C# API Client Proxies or is there any different options for that purpose?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can install the Volo.Abp.Http.Client.IdentityModel.Web package to your project.

    It will try to get access_token from the current HTTPContext and add it to request headers.

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.Http.Client.IdentityModel.Web/Volo/Abp/Http/Client/IdentityModel/Web/HttpContextIdentityModelRemoteServiceHttpClientAuthenticator.cs

  • User Avatar
    0
    uyarbtrlp created

    Is using this package okay on HttpApi.Host application?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38