Open Closed

Elsa integration with authorization #3161


User avatar
0
fareed created
  • ABP Framework version: v5.2.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

I'm having trouble implementing authorization e.g. oauth2 for elsa workflow endpoints when elsa is integrated with abp framework.

app.UseConfiguredEndpoints(endpoints => { // Elsa API Endpoints are implemented as regular ASP.NET Core API controllers. endpoints.MapControllers().RequireAuthorization(); });

https://github.com/elsa-workflows/elsa-core/issues/2681

This configuration as shown above doesn't seem to wrap the workflow endpoints with any kind of authorization. Elsa version is 2.5. Any ideas?

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

2 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    we will check it out.

    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,

    I have checked.

    It works for me:

    But, it's not a good solution, because RequireAuthorization protects all controllers, including Elsa's API controllers. It's like adding [AuthorizeAttribute] to all controllers.

    It breaks the default behavior of all controllers, even though it doesn't require authorization.

    You can check this: https://community.abp.io/posts/using-elsa-workflow-with-the-abp-framework-773siqi9 . It explains protecting elsa dashboard pages based on permissions

    For API endpoints, you can try this:

    public class ElsaActionFilter: IAsyncActionFilter, ITransientDependency
    {
        private readonly ICurrentUser _currentUser;
        private readonly IPermissionChecker _permissionChecker;
    
        public ElsaActionFilter(IPermissionChecker permissionChecker, ICurrentUser currentUser)
        {
            _permissionChecker = permissionChecker;
            _currentUser = currentUser;
        }
    
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (context.Controller.GetType().FullName.StartsWith("Elsa.Server.Api.Endpoints"))
            {
                //elsa api endpoint
                if (!_currentUser.IsAuthenticated)
                {
                    context.Result = new UnauthorizedResult();
                    return;
                }
                
                if (!await _permissionChecker.IsGrantedAsync("PermissionName..."))
                {
                    context.Result = new UnauthorizedResult();
                    return;
                }
                
                await next();
            }
            else
            {
                await next();
            }
        }
    }
    
    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 16, 2026, 07:12
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.