From bcdd25f980b4266df68b2f692b0812f188b7fe66 Mon Sep 17 00:00:00 2001 From: jdevillard Date: Tue, 26 Dec 2023 11:13:01 +0100 Subject: [PATCH] Feature HTTP Activity : Allow adding Authorization Header without validation (#4721) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add capability to add Authorization Header without validation * Refactor authorization header handling in HTTP requests This commit simplifies the syntax for input attributes in the SendHttpRequestBase.cs module. It also renames the boolean value `AddAuthorizatonHeaderWithoutValidation` to `DisableAuthorizationHeaderValidation` for more clarity. This change improves code readability and understanding in relation to handling authorization headers in HTTP requests. --------- Co-authored-by: Jérémie DEVILLARD Co-authored-by: Sipke Schoorstra --- .../Elsa.Http/Activities/SendHttpRequestBase.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modules/Elsa.Http/Activities/SendHttpRequestBase.cs b/src/modules/Elsa.Http/Activities/SendHttpRequestBase.cs index b1e83c0c8..afcc2578e 100644 --- a/src/modules/Elsa.Http/Activities/SendHttpRequestBase.cs +++ b/src/modules/Elsa.Http/Activities/SendHttpRequestBase.cs @@ -57,12 +57,15 @@ public abstract class SendHttpRequestBase : Activity /// The Authorization header value to send with the request. /// /// Bearer {some-access-token} - [Input( - Description = "The Authorization header value to send with the request. For example: Bearer {some-access-token}", - Category = "Security" - )] + [Input(Description = "The Authorization header value to send with the request. For example: Bearer {some-access-token}", Category = "Security")] public Input Authorization { get; set; } = default!; + /// + /// A value that allows to add the Authorization header without validation. + /// + [Input(Description = "A value that allows to add the Authorization header without validation.", Category = "Security")] + public Input DisableAuthorizationHeaderValidation { get; set; } = default!; + /// /// The headers to send along with the request. /// @@ -154,9 +157,13 @@ public abstract class SendHttpRequestBase : Activity var request = new HttpRequestMessage(new HttpMethod(method), url); var headers = context.GetHeaders(RequestHeaders); var authorization = Authorization.GetOrDefault(context); + var addAuthorizationWithoutValidation = DisableAuthorizationHeaderValidation.GetOrDefault(context); if (!string.IsNullOrWhiteSpace(authorization)) - request.Headers.Authorization = AuthenticationHeaderValue.Parse(authorization); + if(addAuthorizationWithoutValidation) + request.Headers.TryAddWithoutValidation("Authorization", authorization); + else + request.Headers.Authorization = AuthenticationHeaderValue.Parse(authorization); foreach (var header in headers) request.Headers.Add(header.Key, header.Value.AsEnumerable());