Skip to content

Commit ac3af7e

Browse files
authored
Merge pull request #477 from serverlessworkflow/fix-http-call-executor
Fix the HttpCallExecutor to configure authentication on the HttpClient used to perform the configured request
2 parents 3b4ed23 + 31b852b commit ac3af7e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/runner/Synapse.Runner/Services/Executors/HttpCallExecutor.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,18 @@ public class HttpCallExecutor(IServiceProvider serviceProvider, ILogger<HttpCall
4949
/// </summary>
5050
protected HttpCallDefinition? Http { get; set; }
5151

52+
/// <summary>
53+
/// Gets the <see cref="AuthenticationPolicyDefinition"/>, if any, to use to perform HTTP calls
54+
/// </summary>
55+
protected AuthenticationPolicyDefinition? Authentication { get; set; }
56+
5257
/// <inheritdoc/>
5358
protected override async Task DoInitializeAsync(CancellationToken cancellationToken)
5459
{
5560
try
5661
{
5762
this.Http = (HttpCallDefinition)this.JsonSerializer.Convert(this.Task.Definition.With, typeof(HttpCallDefinition))!;
58-
var authentication = this.Http.Endpoint.Authentication == null ? null : await this.Task.Workflow.Expressions.EvaluateAsync<AuthenticationPolicyDefinition>(this.Http.Endpoint.Authentication, this.Task.Input, this.Task.Arguments, cancellationToken).ConfigureAwait(false);
59-
using var httpClient = this.HttpClientFactory.CreateClient();
60-
await httpClient.ConfigureAuthenticationAsync(authentication, this.ServiceProvider, this.Task.Workflow.Definition, cancellationToken).ConfigureAwait(false);
63+
this.Authentication = this.Http.Endpoint.Authentication == null ? null : await this.Task.Workflow.Expressions.EvaluateAsync<AuthenticationPolicyDefinition>(this.Http.Endpoint.Authentication, this.Task.Input, this.Task.Arguments, cancellationToken).ConfigureAwait(false);
6164
}
6265
catch(Exception ex)
6366
{
@@ -132,7 +135,8 @@ protected override async Task DoExecuteAsync(CancellationToken cancellationToken
132135
}
133136
var uri = StringFormatter.NamedFormat(this.Http.EndpointUri.OriginalString, this.Task.Input.ToDictionary());
134137
if (uri.IsRuntimeExpression()) uri = await this.Task.Workflow.Expressions.EvaluateAsync<string>(uri, this.Task.Input, this.GetExpressionEvaluationArguments(), cancellationToken).ConfigureAwait(false);
135-
using var httpClient = this.Http.Redirect ? this.HttpClientFactory.CreateClient() : this.HttpClientFactory.CreateClient(RunnerDefaults.HttpClients.NoRedirect); ;
138+
using var httpClient = this.Http.Redirect ? this.HttpClientFactory.CreateClient() : this.HttpClientFactory.CreateClient(RunnerDefaults.HttpClients.NoRedirect);
139+
await httpClient.ConfigureAuthenticationAsync(this.Authentication, this.ServiceProvider, this.Task.Workflow.Definition, cancellationToken).ConfigureAwait(false);
136140
using var request = new HttpRequestMessage(new HttpMethod(this.Http.Method), uri) { Content = requestContent };
137141
if (this.Http.Headers != null)
138142
{

0 commit comments

Comments
 (0)