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?

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    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.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    uyarbtrlp created

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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 24, 2026, 12:09
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.