Abhirock
Abhirock

Reputation: 445

How can I represent 'x-access-token: <token>' in a Swagger Spec (swagger.json)

I am trying to convey that the authentication/security scheme requires setting a header as follows:

x-access-token: <token>

Below is my Security component in Swagger Document which is based on OSA3

   "securitySchemes": {
        "bearerAuth": {
          "type": "http",
          "scheme": "bearer",
          "bearerFormat": "JWT"
        }
      }
    },
    "security": [
      {
        "bearerAuth": []
      }
    ]

But its not working and giving error when I am trying with JWT token as

{
  "success": false,
  "message": "Auth token is not supplied"
}

Please help me where I am doing wrong with securitySchemes?

I have gone though other stackoverflow answer however that useful only when we supply as Authorization: Bearer <token>

Upvotes: 1

Views: 1354

Answers (1)

MarianoBF
MarianoBF

Reputation: 26

A workaround I have used would be to include it as a parameter and later call that parameter for the required paths. This is not as convenient but it will allow testing from the swagger docs page as it sends the authorization header as expected:

components:
 parameters:
   AccessToken:
      name: "x-access-token"
      in: header
      description: Access Token.
      required: true
      schema:
        type: string

And on the required path:

  parameters:
    - $ref: '#components/parameters/AccessToken'

Upvotes: 1

Related Questions