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

Question on the bearer aurhorisation / apikeys

Open heyudude opened this issue 6 years ago • 5 comments

Description

I am writing a website generator for a game Brawlstars, their API is defined and they use bearer auth with api keys limited to IP addresses. If I make a manual get request the response is OK. Via the generated code and some tests the response is "Missing Authorisation" The api url format is:

curl -X GET --header 'Accept: application/json' --header "authorization: Bearer <API token>" 'https://api.brawlstars.com/v1/players/<Player id>'
openapi-generator version

version 3.0.0 and tried also with 3.0.3 format, latest 5.0.0 beta and the 4.3.1 stable

OpenAPI declaration file content or url

the part which is relevant:

servers:
  - url: 'https://api.brawlstars.com/v1'
security:
  - JWT: []

Wrong:

components:         
  securitySchemes:
    JWT:
      type: apiKey
      description: JSON Web Token used as an API key
      in: header
      name: authorisation

Correct:

components:         
  securitySchemes:

    JWT:
        type: http
        scheme: bearer
        bearerFormat: JWT
Command line used for generation
java -jar openapi-generator-cli.jar generate -g python -i ../brawlstars-swagger/bs_swagger.yaml --config ../brawlstars-swagger/bs_config.yaml 

Config:

generatorName: python
outputDir: .
inputSpec: bs_swagger.yaml
templateDir: ../brawlstars-swagger/python
additionalProperties:
  packageName: pybrawl
Suggest a fix/enhancement

Any help would be appreciated! Thanks for this wonderful toolset

heyudude avatar Jul 27 '20 11:07 heyudude

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

auto-labeler avatar Jul 27 '20 11:07 auto-labeler

I figured out the above question by hard coding the value for access_token in the configuration.py Now the api call succeeds!

Next question: where to initialize the value correctly from my settings file I use? Because access_token needs to be assigned manually to has it seems

heyudude avatar Jul 28 '20 10:07 heyudude

Found the solution... no replies unfortunately o a valid question: why?

heyudude avatar Aug 09 '20 06:08 heyudude

@heyudude can you share the solution? I'm facing the same problem.

GabeL7r avatar Aug 16 '20 05:08 GabeL7r

@GabeL7r Sure. Anytime here to help, this piece of yaml generated the correct code in my API module I had to check also for old and floating modules: I cleaned them all before I build a new one with this change. Just to double check. My yaml can be found at https://github.com/heyudude/brawlstars-swagger I figured out the above question by hard coding the value for access_token in the configuration.py Now the api call succeeds! And the API code is called pybrawl. Good luck with the solution and if I need to peek and help, let me know.

security:
  - JWT: []

components:
  securitySchemes:
    JWT:
        type: http
        scheme: bearer
        bearerFormat: JWT

heyudude avatar Aug 16 '20 06:08 heyudude