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

[typescript-axios] Generating bearerAuth create Basic auth instead #1446

Closed
chattersley opened this issue Nov 14, 2018 · 6 comments
Closed

Comments

@chattersley
Copy link

Description

Attempting to generate from an openapi definition with bearerAuth marked as the security schema. When it generates using axios-typescript it generates Basic auth security instead? It does generate a comment referencing Bearer auth but no code to add the header.

openapi-generator version

"@harmowatch/openapi-generator-cli": "0.0.3-3.3.2"

OpenAPI declaration file content or url
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

This generates

            // authentication bearerAuth required
            // http basic authentication required
            if (
                configuration &&
                (configuration.username || configuration.password)
            ) {
                localVarHeaderParameter["Authorization"] =
                    "Basic " +
                    btoa(configuration.username + ":" + configuration.password);
            }
Command line used for generation

Generating through npm.
npm=6.2.0
node=v10.9.0
"generate": "openapi-generator generate -i api/myapi.yaml -g typescript-axios -o generated-sources/myapi"

Steps to reproduce

Running generate commmand.

Suggest a fix/enhancement
@mbayou
Copy link

mbayou commented Nov 15, 2018

Hi,

This issue exists for typescript-angular too.

components
  securitySchemes:
    bearerAuth:            
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - bearerAuth: []

And my generated code:

// authentication (bearerAuth) required
if (this.configuration.username || this.configuration.password) {
    headers = headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
}

@vmorris
Copy link

vmorris commented Dec 11, 2018

Python too #1577

@ceefour
Copy link

ceefour commented Jan 20, 2019

This issue exists for typescript-fetch too. Please implement...

davidwcarlson added a commit to davidwcarlson/openapi-generator that referenced this issue Jan 24, 2019
See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send "Authorization: Basic [base64Encode(username + ":" + password)]"
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer

This change will generate an OAuth header, which will send a "Authorization: Bearer [accessToken]"
This is a smaller, less-impactful change than introducing a BearerAuth object, but this change doesn't support scheme values other than bearer
See also OpenAPITools#1930
davidwcarlson added a commit to davidwcarlson/openapi-generator that referenced this issue Jan 24, 2019
See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools@80ca67c

This PR is an alternative to OpenAPITools#1972
wing328 pushed a commit that referenced this issue Feb 9, 2019
* fix #457 by introducing an HttpBearerAuth object

See #457
Also #1446 for typescript, #1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of 80ca67c

This PR is an alternative to #1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this issue Feb 27, 2019
* fix OpenAPITools#457 by introducing an HttpBearerAuth object

See OpenAPITools#457
Also OpenAPITools#1446 for typescript, OpenAPITools#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools@80ca67c

This PR is an alternative to OpenAPITools#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
hectorj added a commit to hectorj/openapi-generator that referenced this issue Apr 2, 2019
It was generated the same as Basic authentication. Now we handle both cases differently.

Fix OpenAPITools#1446
wing328 pushed a commit that referenced this issue Apr 4, 2019
* [typescript-axios] Fix Bearer authentication

It was generated the same as Basic authentication. Now we handle both cases differently.

Fix #1446

* [typescript-axios] Bearer authentication : use config.accessToken instead of config.password

As it is done in the angular client: https://github.com/OpenAPITools/openapi-generator/blob/0889b8ec1349d6f912ad7dfa221d3980f1801dba/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache#L213-L220
@AbhimanyuG
Copy link

AbhimanyuG commented Apr 18, 2019

I still see the same issue in NPM wrapper and latest docker image (generated 7 hours ago). Issue exists in typescript-fetch.

@murugaratham
Copy link

i am using npm wrapper and still not able to get bearer auth templates

@vinguan
Copy link

vinguan commented Nov 11, 2019

Is this fixed? I am trying to generate clients using it and it does not generate the setter the Bearer header.

therve pushed a commit to DataDog/datadog-api-client-java that referenced this issue Mar 23, 2021
* fix #457 by introducing an HttpBearerAuth object

See OpenAPITools/openapi-generator#457
Also OpenAPITools/openapi-generator#1446 for typescript, OpenAPITools/openapi-generator#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools/openapi-generator@80ca67c

This PR is an alternative to OpenAPITools/openapi-generator#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
api-clients-generation-pipeline bot pushed a commit to DataDog/datadog-api-client-java that referenced this issue Sep 8, 2021
* fix #457 by introducing an HttpBearerAuth object

See OpenAPITools/openapi-generator#457
Also OpenAPITools/openapi-generator#1446 for typescript, OpenAPITools/openapi-generator#1577 for python

Specs defined as follows currently generate BasicAuth and send an "Authorization: Basic [base64Encode(username + ":" + password)]" header
    components:
      securitySchemes:
        bearer:
          type: http
          scheme: bearer

This change will generate code which uses a new HttpBearerAuth class, which will send a "Authorization: [scheme] [accessToken]" header.
This change is slightly larger and more impactful than simply using OAuth for bearerBearer, but it allows for scheme values other than bearer.

This fix was enabled by the recent commit of OpenAPITools/openapi-generator@80ca67c

This PR is an alternative to OpenAPITools/openapi-generator#1972

* update petstore samples

* Update HttpBearerAuth mustache templates and samples

* correct the expected number of generated java client files

* update the retrofit2 HttpBearerAuth template and samples

* Add resttemplate-specific HttpBearerAuth mustache and samples

* add vertx-specific HttpBearerAuth template and samples

* add java webclient-specific HttpBearerAuth template and samples
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants