Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][csharp] Bearer token not added when using AccessToken configuration #20004

Open
6 tasks done
Magnuti opened this issue Oct 31, 2024 · 0 comments
Open
6 tasks done

Comments

@Magnuti
Copy link

Magnuti commented Oct 31, 2024

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using either of these two configurations does not set the Authorization: Bearer <access_token> header.

var configuration = new Configuration
{
    AccessToken = accessToken
}
var configuration = new Configuration
{
    ApiKeyPrefix = new Dictionary<string, string>
    {
        { "Authorization", "Bearer" }
    },
    ApiKey = new Dictionary<string, string>
    {
        { "Authorization", accessToken }
    }
}

But using DefaultHeaders seems to work. This is counter intuitive - the AccessToken configuration property should either be fixed or removed.

// This works but it is ugly
var configuration = new Configuration
{
    DefaultHeaders = new Dictionary<string, string>
    {
         { "Authorization", $"Bearer {accessToken}" }
    }
}
openapi-generator version

openapitools/openapi-generator-cli:latest

OpenAPI declaration file content or url

https://api.signicat.com/info/lookup/swagger/v1/swagger.json

Generation Details
docker run --rm --volume "${PWD}:/generated" openapitools/openapi-generator-cli generate \
    -i https://api.signicat.com/info/lookup/swagger/v1/swagger.json \
    -g csharp \
    -o /generated \
    --additional-properties=targetFramework=net8.0
Steps to reproduce
  1. Run the docker command above
  2. Set the authorization token either with the AccessToken configuration property or by the ApiKeyPrefix + ApiKey configuration properties.
  3. Send a request
  4. Inspect the request headers
  5. See that Authorization: Bearer <access_token> is not present
Related issues/PRs
Suggest a fix

Remove the non-working configuration properties or fix them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant