Starts in:
2 DAYS
23 HRS
8 MIN
33 SEC
Starts in:
2 D
23 H
8 M
33 S
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<TimeSeriesMetaDataDto> CreateAsync(TimeSeriesMetaDataCreateDto inputDto)
    {
        //Added record to the database
    }
}

public class ResCsvIngestJob : AsyncBackgroundJob<ResCsvIngestArgs>, 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)
  • User Avatar
    1
    Denis created

    I have similar issue. I have 2 modules A and B. Module A has Background Job which calls endpoint in module B. Background Job gets exception AbpAuthoizationException because endpoint is protected with permission

    My qestions about that https://support.abp.io/QA/Questions/1364/Authorization-in-event-handlers https://support.abp.io/QA/Questions/1347/Distributed-Events-in-monolith

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Thanks Denis

    Let's discuss this in your questions. I refunded question credit to jason.

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