dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Cannot add value because header 'Authorization' does not support multiple values.

Open jacekwielek opened this issue 9 months ago • 0 comments

Checklist

  • [x] I have looked into the README and have not found a suitable solution or answer.
  • [x] I have looked into the documentation and have not found a suitable solution or answer.
  • [x] I have searched the issues and have not found a suitable solution or answer.
  • [x] I have upgraded to the latest version of OpenFGA and the issue still persists.
  • [x] I have searched the Slack community and have not found a suitable solution or answer.
  • [x] I agree to the terms within the OpenFGA Code of Conduct.

Description

When I pass httpClient the OpenFgaApi and use CredentialsMethod.ApiToken authorization then I've got runtime exception about duplicated Authorization http header.

The exact exception: Cannot add value because header 'Authorization' does not support multiple values.

Expectation

No exception thrown.

Reproduction

    /// <summary>
    /// Test that reusing custom HttpClient is possible
    /// </summary>
    [Fact]
    public async Task UseCustomHttpClient() {
        var config = new Configuration.Configuration() {
            ApiHost = _host,
            Credentials = new Credentials {
                Method = CredentialsMethod.ApiToken,
                Config = new CredentialsConfig { ApiToken = "123" }
            }
        };

        var customHttpClient = new HttpClient();
        var openFgaApiCreation = () => new OpenFgaApi(config, customHttpClient);
        openFgaApiCreation();

        var exception = Record.Exception(() => openFgaApiCreation());
        Assert.Null(exception);
    }

OpenFGA SDK version

Source code from 28.01.2025

OpenFGA version

Source code from 28.01.2025

SDK Configuration

According to the documentation

Logs

System.FormatException: Cannot add value because header 'Authorization' does not support multiple values. at System.Net.Http.Headers.HttpHeaders.ParseAndAddValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value) at System.Net.Http.Headers.HttpHeaders.Add(HeaderDescriptor descriptor, String value) at System.Net.Http.Headers.HttpHeaders.Add(String name, String value) at OpenFga.Sdk.ApiClient.BaseClient..ctor(Configuration configuration, HttpClient httpClient) in D:\Code\dotnet-sdk\src\OpenFga.Sdk\ApiClient\BaseClient.cs:line 55 at OpenFga.Sdk.ApiClient.ApiClient..ctor(Configuration configuration, HttpClient userHttpClient) in D:\Code\dotnet-sdk\src\OpenFga.Sdk\ApiClient\ApiClient.cs:line 39 at OpenFga.Sdk.Api.OpenFgaApi..ctor(Configuration configuration, HttpClient httpClient) in D:\Code\dotnet-sdk\src\OpenFga.Sdk\Api\OpenFgaApi.cs:line 35 at OpenFga.Sdk.Test.Api.OpenFgaApiTests.<>c__DisplayClass8_0.<UseCustomHttpClient>b__0() in D:\Code\dotnet-sdk\src\OpenFga.Sdk.Test\Api\OpenFgaApiTests.cs:line 104 at OpenFga.Sdk.Test.Api.OpenFgaApiTests.<>c__DisplayClass8_0.<UseCustomHttpClient>b__1() in D:\Code\dotnet-sdk\src\OpenFga.Sdk.Test\Api\OpenFgaApiTests.cs:line 108 at Xunit.Record.Exception(Func`1 testCode) in /_/src/xunit.core/Record.cs:line 47

References

No response

jacekwielek avatar Jan 29 '25 07:01 jacekwielek