fix(workflows): authenticate the BPMN API client - #1036
Merged
Merged
Conversation
AddWorkflowsCore() registered IBpmnInterchangeApi with .AddRemoteApi<T>() and no BackendApiConfig, so its Refit client never picked up the host's AuthenticationHandler and every BPMN call (analyze/import/export/document) came back 401 for an otherwise-authenticated session. Move the registration to a new AddWorkflowsModule(BackendApiConfig) overload, mirroring AddDashboardModule's pattern, and thread the host's config through it from every host and sample that owns one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1034. Part of elsa-workflows/elsa-core#7909.
Problem
In a live run (Elsa.Server.Web plus Elsa.Studio.Host.Server, signed in as admin), every BPMN call from Studio returned 401, while the other clients on the same session got 200:
AddWorkflowsCoreregistered the local Refit client as.AddRemoteApi<IBpmnInterchangeApi>()without aBackendApiConfig, so the client never got the host'sAuthenticationHandler. Import BPMN, Export BPMN and the Performed-by panel were all unusable against an authenticated server. The bug came in with #1012. The unit tests missed it because they fakeIBackendApiClientProvider.Fix
This follows the
AddDashboardModule/AddDashboardModule(BackendApiConfig)pattern:AddWorkflowsModule(BackendApiConfig backendApiConfig), registers the module and thenAddRemoteApi<IBpmnInterchangeApi>(backendApiConfig).AddWorkflowsCore.Microsoft.Extensions.Httpregistrations for the same client name add up rather than replace each other, so keeping it would have left two competing pipelines.backendApiConfigit already builds:Host.Server,Host.Wasm,Host.CustomElementsandsamples/BlazorApp1.Host.HostedWasmdoes not call the module. The snippet in the Dashboard README is updated, since it is the only doc that shows the call.Compatibility note: a third-party host that keeps calling the parameterless
AddWorkflowsModule()still gets an unauthenticated BPMN client. That is the same behaviour as the parameterlessAddDashboardModule()today. Such hosts should switch to the config overload, as every host in this repo now does.Tests
WorkflowsModuleAuthenticationTestsbuilds the container the way a real host does (AddRemoteBackendplusAddWorkflowsModule(backendApiConfig)) and swaps only the primaryHttpMessageHandler. It then calls the real registered client and asserts that the header stamped by the configured authentication handler is present.Elsa.Studio.Workflows.Tests: 447/447. The full solution builds on all TFMs.🤖 Generated with Claude Code