Forum Discussion

rahuldwivedi's avatar
rahuldwivedi
New Contributor
5 years ago

JTW token is not getting passed in Swagger-ui

JWT token is not getting passed under 'Authorization' feild.

Here's the full post https://stackoverflow.com/questions/63119252/jtw-token-is-not-getting-passed-in-swagger-ui

  • Hi rahuldwivedi,

    Make sure your API definition includes the "security" key on the root level or in operations. For example:

    swagger: '2.0'
    securityDefinitions:
      ApiKeyAuth:
        type: apiKey
        in: header
        name: Authorization
    security:  # <-------------
      - ApiKeyAuth: []

    Check out our OpenAPI 2.0: API Keys guide for more examples.

  • HKosova's avatar
    HKosova
    5 years ago

    Replace

        "security":{
            "ApiKeyAuth": []
        },

    with

      "security": [
        {
          "ApiKeyAuth": []
        }
      ],

     

    Swagger Editor is a YAML editor, but you can also paste JSON and import JSON files. JSON will be automatically converted to YAML. Then after you fixed the errors you can use the "File > Convert and save as JSON" command to export back to JSON.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Hi rahuldwivedi,

    Make sure your API definition includes the "security" key on the root level or in operations. For example:

    swagger: '2.0'
    securityDefinitions:
      ApiKeyAuth:
        type: apiKey
        in: header
        name: Authorization
    security:  # <-------------
      - ApiKeyAuth: []

    Check out our OpenAPI 2.0: API Keys guide for more examples.

    • rahuldwivedi's avatar
      rahuldwivedi
      New Contributor

      Hey HKosova  thanks for the reply. Looks like I'm missing something more here.  When I added the field and hit execute, the UI keeps on showing the loader, this is what I'm getting on console.:

       

      system.js:464 TypeError: f.forEach is not a function
      at t.request (build-request.js:81)
      at fn (build-request.js:15)
      at Object.gn [as buildRequest] (index.js:249)
      at actions.js:428
      at Object.dispatch (utils.js:195)
      at dispatch (<anonymous>:1:28545)
      at redux.js:477
      at wrap-actions.js:33
      at Object.r (system.js:174)
      at Object.executeRequest (system.js:461)

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Paste your API definition into https://editor.swagger.io to check if there are any syntax errors. If the editor shows any errors, you'll need to fix them before using "try it out".

         

        If this does not help, can you attach your API definition (or a minimal example) here so that we could reproduce the issue?