Skip to content

HttpRequest doesn't send parameters added in Authenticator #2061

@hmG3

Description

@hmG3

Describe the bug
After upgrading from version 109.1 to 110.0 I noticed some of our logic is broken.
A typical use case for us is to add security headers during the authentication flow.

public override ValueTask Authenticate(IRestClient client, RestRequest request)
{
    request.AddOrUpdateParameter("X-Security-Param", "generated-security-hash");
    return ValueTask.CompletedTask;
}

However, it doesn't work when sending requests with form data.

While investigating, I found that now when building RequestContent

using var requestContent = new RequestContent(this, request);

for HttpRequestMessage it adds only cached params
var postParameters = _parameters.GetContentParameters(_request.Method).ToArray();

but not ones added by Authenticator
if (authenticator != null) await authenticator.Authenticate(this, request).ConfigureAwait(false);

To Reproduce

public class RestWrapper : IAuthenticator
{
    private readonly RestClient _restClient;

    public RestWrapper()
    {
        _restClient = new RestClient(new RestClientOptions
        {
            BaseUrl = new Uri("https://localhost"),
            Authenticator = this
        });
    }

    public ValueTask Authenticate(IRestClient client, RestRequest request)
    {
        request.AddParameter("X-Security-Param", "generated-security-hash");
        return ValueTask.CompletedTask;
    }

    public void SendRequest()
    {
        var testRequest = new RestRequest("api/v1/endpoint", Method.Post);
        testRequest.AddParameter("scope", "test");

        _restClient.Execute(testRequest);
    }
}

new RestWrapper().SendRequest() // server failure - missing X-Security-Param

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions