Open Closed

Cannot get the CurrentTenant.Id while using the ELSA #3966


User avatar
0
uyarbtrlp created
  • ABP Framework version: v.6.0.1

  • UI type: MVC

  • DB provider: EF Core

  • Tiered (MVC): yes

  • Exception message and stack trace:

  • Steps to reproduce the issue:"

Hello,

I've implemented the ELSA for our workflow requirement according to https://community.abp.io/posts/integrating-elsa-.net-workflows-with-abp-commercial-io32k420 and https://community.abp.io/posts/using-elsa-workflow-with-the-abp-framework-773siqi9. It runs perfectly, but when we want to distinguish the workflows between tenants, I need to get the tenant id from somewhere. They've written the CustomTenantAccessor to access and change the tenant id. Here is the example: https://github.com/elsa-workflows/elsa-core/blob/bc6013aabc7cdbdb8bee336f52f99fb9e341e533/src/samples/aspnet/Elsa.Samples.CustomTenantIdSource/CustomTenantAccessor.cs. I thought that I can use the ICurrentTenant service to get the tenant information. Unfortunately, It is retrieved as null and I couldn't use the multi tenancy option on the ELSA. Here is the steps that I followed:

  1. Create a clean project by using the abp suite (Application Template & Tiered)

  2. Add the regarding packages into the relevant layers

Domain ->

PackageReference Include="Elsa" Version="2.9.1" 
PackageReference Include="Elsa.Activities.Console" Version="2.9.1" 
PackageReference Include="Elsa.Activities.Http" Version="2.9.1" 
PackageReference Include="Elsa.Activities.Email" Version="2.9.1" 
PackageReference Include="Elsa.Activities.Temporal.Quartz" Version="2.9.1" 

EntityFrameworkCore ->

PackageReference Include="Elsa.Persistence.EntityFramework.SqlServer" Version="2.9.1"

HttpApi ->

 PackageReference Include="Elsa.Server.Api" Version="2.9.1" 

Web ->

PackageReference Include="Elsa.Designer.Components.Web" Version="2.9.1"
  1. Insert a new class named as CustomTenantAccessor
    image.png

  2. Configure the ELSA on HttpApi.Host module and add api versioning (ELSA uses).
    image.png
    image.png
    image.png

  3. Add api versioning on Web module as above

  4. Insert Elsa.cshmtl and Elsa.cshtml.cs under Pages folder on Web
    image.png

  5. Add the HttpApi.Host url into the appsettings.json as CorsOrigins to prevent CORS
    image.png

  6. Navigate to /elsa on Web and see the CurrentTenant value on CustomTenantAccessor. It is empty.
    image.png
    image.png

  7. When I send the request to one of the ELSA endpoints on Swagger, I can see that the tenant information is fulfilled and there are headers regarding cookies, authorization etc.
    image.png

It seems that there are some missing parts while sending the request. Since there are no information about how to implement the multi tenancy on ELSA, there could be some missing parts on my implementation. How can I get the tenant id for the ELSA endpoints while working on ELSA dashboard?


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

    Hi.

    Could you share a project with me that can reproduce the problem? thanks. shiwei.liang@volosoft.com

  • User Avatar
    0
    uyarbtrlp created

    Hello,

    I've sent it. Thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can try this:

    public class ElsaModel : PageModel
    {
       public string Token { get; set; }
       
       public async Task OnGetAsync()
       {
           Token = await HttpContext.GetTokenAsync("access_token");
       }
    }
    
    ....
    
    <body class="h-screen" style="background-size: 30px 30px; background-image: url(/_content/Elsa.Designer.Components.Web/elsa-workflows-studio/assets/images/tile.png); background-color: #FBFBFB;">
    	<elsa-studio-root server-url="@serverUrl" monaco-lib-path="_content/Elsa.Designer.Components.Web/monaco-editor/min"><elsa-studio-dashboard></elsa-studio-dashboard></elsa-studio-root>
    
        <script>
    		function AuthorizationMiddlewarePlugin(elsaStudio) {
    			const eventBus = elsaStudio.eventBus;
    		
    			eventBus.on('http-client-created', e => {
    				// Register Axios middleware.
    				e.service.register({
    					onRequest(request) {
    						request.headers = { 'Authorization': 'Bearer @Model.Token' }
    						return request;
    					}
    				});
    			});
    		}
    		
    		const elsaStudioRoot = document.querySelector('elsa-studio-root');
            
    			 elsaStudioRoot.addEventListener('initializing', e => {
    			const elsaStudio = e.detail;
    			elsaStudio.pluginManager.registerPlugin(AuthorizationMiddlewarePlugin);
             });
        </script>
    </body>
    ....
    

    1667291665523.jpg

  • User Avatar
    0
    uyarbtrlp created

    It works as expected, but I've faced 415 error while publishing a new workflow definition on dashboard. I've inserted 'Content-Type':'application/json' in request.headers

    Thanks a lot!

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Sorry, try this:

    eventBus.on('http-client-created', e => {
        // Register Axios middleware.
        e.service.register({
        	onRequest(request) {
        	    request.headers["Authorization"] = "Bearer @Model.Token";
        	    return request;
        	}
        });
    });
    

    I was follow the document: https://elsa-workflows.github.io/elsa-core/docs/next/extensibility/extensibility-designer-plugins#intercept-outgoing-http-requests

    But it's not correct, because It replaces the entire request header

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.2.0-preview. Updated on March 13, 2025, 04:08