Open Closed

AsyncBackgroundJob using AppService with Authorize attributes #1371


User avatar
1
jason.smith created
  • ABP Framework version: v3.2.1

  • UI type: Angular

  • DB provider: EF Core

  • Tiered (MVC) or Identity Server Separated (Angular): no

  • Exception message and stack trace: none

  • Steps to reproduce the issue:

    1. AsyncBackgroundJob that calls an AppService with and [Authorize] attribute on the method called.

Looking for the correct method to supply the calling users permissions / authorisations to a background job so that long running actions can be performed on behalf of that user.

[Authorize(ReprosPermissions.TimeSeriesMetaData.Default)]
public class TimeSeriesMetaDataAppService : ApplicationService, ITimeSeriesMetaDataAppService
{
    [Authorize(ReprosPermissions.TimeSeriesMetaData.Create)]
    public virtual async Task CreateAsync(TimeSeriesMetaDataCreateDto inputDto)
    {
        //Added record to the database
    }
}

public class ResCsvIngestJob : AsyncBackgroundJob, ITransientDependency
{
    public ResCsvIngestJob(
        ITimeSeriesMetaDataAppService timeSeriesMetaDataAppService)
    {
        _timeSeriesMetaDataAppService = timeSeriesMetaDataAppService;
    }

    public override async Task ExecuteAsync(ResCsvIngestArgs args)
    {
        //How do I call the following without getting the auth exception?
        await _timeSeriesMetaDataAppService.CreateAsync(new TimeSeriesMetaDataCreateDto());
    }
}

2 Answer(s)
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 April 11, 2025, 10:10