Feature HTTP Activity : Allow adding Authorization Header without validation (#4721)

* 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 <jdevillard@users.noreply.github.com>
Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
This commit is contained in:
jdevillard 2023-12-26 11:13:01 +01:00 committed by GitHub
parent 3dc7ceb71d
commit bcdd25f980
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,12 +57,15 @@ public abstract class SendHttpRequestBase : Activity<HttpResponseMessage>
/// The Authorization header value to send with the request.
/// </summary>
/// <example>Bearer {some-access-token}</example>
[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<string?> Authorization { get; set; } = default!;
/// <summary>
/// A value that allows to add the Authorization header without validation.
/// </summary>
[Input(Description = "A value that allows to add the Authorization header without validation.", Category = "Security")]
public Input<bool> DisableAuthorizationHeaderValidation { get; set; } = default!;
/// <summary>
/// The headers to send along with the request.
/// </summary>
@ -154,9 +157,13 @@ public abstract class SendHttpRequestBase : Activity<HttpResponseMessage>
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());