Starts in:
2 DAYS
0 HR
12 MIN
4 SEC
Starts in:
2 D
0 H
12 M
4 S
Open Closed

BackgroundJob Authorization While Using Remote Service Call #5632


User avatar
0
uyarbtrlp created
  • ABP Framework version: v7.3.1
  • UI Type: MVC
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..)
  • Module Template (Separated Deployment & Databases Scenario): yes

Hello,

As I've mentioned here , I call the file management app service, which is implemented on AuthService as if it is a microservice, on my domain service by using remote service call. I use static proxy scripts to achieve that. When I call it, I get an authorization error since we don't have httpContext access on background job. I implement AbpHttpClientIdentityModelWebModule on HttpApi.Host to pass the current token to authorization header (not using the AbpHttpClientIdentityModelModule with client_credentials flow)

Here is the part of my domain service method (ExportAsBaseModelAsync) which uses fileDescriptorAppService:

Here is the background job:

Here is the error log on HttpApi.Host and AuthServer

How can I send the request behalf of the user with current token? Is there a way to do that magically like ApplicationService methods?


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

    Hi,

    The Background Job means that it has nothing to do with the current request. It is another separate thread.

    If you want to use the token of the current user, then you should not call remote services in the background job.

  • User Avatar
    0
    uyarbtrlp created

    Is using the client credentials flow suggested if I want to use the remote service in the background job?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Yes, it is, That's what it does in the microservice template.

    https://docs.abp.io/en/commercial/latest/startup-templates/microservice/synchronous-interservice-communication#configuring-auto-discovery-endpoint

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06