openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][csharp-netcore] bearerAuth is interpreted as basicAuth

Open FaFre opened this issue 6 years ago • 4 comments

Description

I added a bearer authentication in my description according to the the swagger docs:

"components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
...
"security": [
    {
      "bearerAuth": []
    }
  ]

But for some reasons the generated code contains an basicAuth with username/password instead of the bearer expected as Authorization: Bearer <token>:

DefaultApi.cs:

// authentication (bearerAuth) required
            // http basic authentication required
            if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password))
            {
                localVarRequestOptions.HeaderParameters.Add("Authorization", "Basic " + Org.OpenAPITools.Client.ClientUtils.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password));
            }
openapi-generator version

I use the docker image:

$ openapi-generator-cli version
4.3.1-SNAPSHOT
OpenAPI declaration file content or url

Gist

Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate -i https://gist.githubusercontent.com/FaFre/b15e59572a974a9f453d14e5cdaf3bec/raw/d40a46cb20d70dd41abbf19691745f2ffb5a1f04/test.json -g csharp-netcore -o /local/

FaFre avatar Apr 13 '20 18:04 FaFre

@FaFre thanks for reporting the issue. I've filed #5921 to fix it.

wing328 avatar Apr 14 '20 03:04 wing328

Looks like it is still not fixed in async client

codemnk avatar May 01 '20 21:05 codemnk

@codemnk my bad that I missed it in my previous PR. I've filed https://github.com/OpenAPITools/openapi-generator/pull/6136 to fix it.

wing328 avatar May 02 '20 13:05 wing328

@codemnk the fix has been merged into master. Please give it another try.

wing328 avatar May 04 '20 06:05 wing328