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

Open
#89 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
csharp

Research direction

Start in src/OpenFga.Sdk/ApiClient/BaseClient.cs at line 55 and inspect the OpenFgaApi and ApiClient construction shown in the stack trace. Use src/OpenFga.Sdk.Test/Api/OpenFgaApiTests.cs, especially UseCustomHttpClient, as the regression case. Done means creating OpenFgaApi twice with the same custom HttpClient and ApiToken completes without an exception.

Written by the indexing model from the issue text.

Description

enhancement
Checklist
  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of OpenFGA and the issue still persists.
  • I have searched the Slack community and have not found a suitable solution or answer.
  • 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.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.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

Dominant language
C#
Stars
85
Forks
18
Avg merge
23h 28m
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openfga/dotnet-sdk

All issues in openfga/dotnet-sdk

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.