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

[BUG] setApiKeyToObject & setBearerAuthToObject functions set header to undefined

Open johnwc opened this issue 2 years ago • 3 comments

Bug Report Checklist

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

When the apiKey and accessToken config settings are functions, setApiKeyToObject, setBearerAuthToObject , etc... will set the header values to undefined or empty string if the config function returns either.

openapi-generator version

6.0.1

Suggest a fix

The setApiKeyToObject, setBearerAuthToObject, etc... functions need to check if the localVarApiKeyValue, accessToken, etc... local variable is undefined; if so, then do not add the key to the object. When the apiKey and accessToken config settings are a function and there is multiple possible authentication schemes for a rest api(api key, bearer, etc...), we need to be able to tell the setApiKeyToObject, setBearerAuthToObject , etc... functions that we do not want to add the header to the request object.

johnwc avatar Aug 26 '22 04:08 johnwc

can you please file a PR with the suggested fix? thanks

wing328 avatar Aug 26 '22 06:08 wing328

Authentication/authorization is in general broken and should be really looked into , at least when generating aspnetcore , messy code is generated that does not register a defaultScheme ect pp I am so far that I dont doc apikeys in the spec file and write some own simple check , its a workaround but not a solution

Karstenx1971 avatar Sep 18 '22 03:09 Karstenx1971

We have asp.net core APIs that it generates perfectly for. One of out API servers even has 3 different authentication schemes. One oauth bearer and the other two api key based.

johnwc avatar Sep 18 '22 03:09 johnwc