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

[javascript, typescript-node] HTTP / Bearer Scheme does not generate clients that use Bearer Tokens #1133

Closed
johnkoerner opened this issue Sep 27, 2018 · 13 comments

Comments

@johnkoerner
Copy link

johnkoerner commented Sep 27, 2018

Description

Setting up an API that uses a bearer token should result in clients that send the Bearer XXXX value in the Authorization header. However the javascript and typescript-node clients generate code that wants to send a username/password combination in the header.

openapi-generator version

3.2.3

OpenAPI declaration file content or url
components:
  securitySchemes:
    bearerAuth:            # arbitrary name for the security scheme
      type: http
      scheme: bearer
      bearerFormat: JWT  

Full sample: https://gist.github.com/johnkoerner/952becd82bbb238b51907791d0a13d32

Command line used for generation
openapi-generator generate -i Test.yaml -g typescript-node -o ./ts
Steps to reproduce

Generate a typescript-node or javascript client that uses authentication with the bearer scheme.

Suggest a fix/enhancement

When the bearer scheme is specified, then the Authorization header should be specified with the Bearer {accessToken} format. It appears that the OAuth2 flow already supports the Bearer token format.

Note: I only tested with javascript and typescript-node other client generators may have similar issues.

@CaptEmulation
Copy link

Not sure that any clients support it. Looking at https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L3034-L3087 there does not seem to be any bearer support

@Gabrn
Copy link

Gabrn commented Jan 7, 2019

Same issue for typescript-axios

@wing328
Copy link
Member

wing328 commented Jan 8, 2019

@wing328
Copy link
Member

wing328 commented Jan 8, 2019

@mrvdot
Copy link

mrvdot commented Jan 12, 2019

[Update: Just realized #1470 is already merged]

I should be able to update the JS/TS clients. I need it fixed in typescript-axios for a current project anyway.

@mrvdot
Copy link

mrvdot commented Jan 13, 2019

Working on this at https://github.com/mrvdot/openapi-generator/tree/enable-bearer-auth-js-ts. This is my first change for the generator, so any comments/critiques are welcome.

  • typescript-axios
  • typescript-fetch
    • I added the bearer auth to this, however couldn't get the generated API to work (appears to be something wrong with the configuration class). Will review again after updating the rest, but believe the bearer auth change is correct.
  • javascript (does not appear to have basic auth implemented yet either)
  • javascript-es6 (does not appear to have basic auth implemented yet either)
  • typescript-angular
  • typescript-angularjs
  • typescript-aurelia
  • typescript-inversify
  • typescript-jquery
  • typescript-node

@Gabrn
Copy link

Gabrn commented Jan 16, 2019

Any news on this?

@mrvdot
Copy link

mrvdot commented Jan 16, 2019

@Gabrn typescript-axios and typescript-fetch are done, and you're welcome to build from the repo mentioned above if you need those now. I probably won't have time for the others until this weekend

@wing328 wing328 modified the milestones: 4.0.0, 4.0.1 May 13, 2019
@wing328 wing328 modified the milestones: 4.0.1, 4.0.2 May 31, 2019
@wing328 wing328 modified the milestones: 4.0.2, 4.0.3 Jun 20, 2019
@MilanParikh
Copy link

@mrvdot For the typescript-fetch generator I believe the issue with the configuration class is here

I generated an API and realized that the accessKey field takes an optional scopes parameter but apiKey does not, and either of those can be used for bearer auth. Hopefully this is helpful?

@wing328 wing328 modified the milestones: 4.0.3, 4.1.0 Jul 9, 2019
@grokify
Copy link
Member

grokify commented Jul 21, 2019

Just found this issue because the Go / Golang client has the same issue. When specifying a bearer token, basicAuth is implemented.

Of note, in addition to taking an access token, it would be nice to take a refresh token as well so the client can refresh the token itself.

This is something Go can do as I'm passing in a custom Go *http.Client with this capability to the client now. When I do this, I can use a static non-expiring token or a *http.Client that will refresh the token.

@wing328 wing328 modified the milestones: 4.1.0, 4.1.1 Aug 9, 2019
@quezak
Copy link

quezak commented Aug 23, 2019

Hello! do you have any updates on this?
I see that this was already fixed as a bug for typescript-axios, but I see it's still not implemented in typescript-node, don't know about the other tyepscript targets.

@wing328 wing328 modified the milestones: 4.1.1, 4.1.2 Aug 26, 2019
@wing328 wing328 modified the milestones: 4.1.2, 4.1.3 Sep 11, 2019
@wing328 wing328 removed this from the 4.1.3 milestone Oct 4, 2019
@wing328 wing328 added this to the 4.2.0 milestone Oct 4, 2019
@wing328 wing328 removed this from the 4.2.0 milestone Oct 30, 2019
@macjohnny
Copy link
Member

implemented for typescript-node in #4633

MarcBaldi added a commit to MarcBaldi/openapi-generator that referenced this issue Mar 18, 2021
I just tested bearer token in our Project and it works.
I think it was implemented for this issue:
OpenAPITools#1133
They did not mention typescript-angular specificly, so maybe i am wrong
@Huluti
Copy link

Huluti commented Jan 27, 2024

@wing328 can be closed i think :)

@wing328 wing328 closed this as completed Jan 28, 2024
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

10 participants