Swagger and JWT Token Authentication

前端 未结 2 1750
耶瑟儿~
耶瑟儿~ 2021-01-15 23:52

I am building some Swagger documentation, all well and good, except that I am wanting to have the page work interactively, so when selecting the editor or UI, if I hit the a

2条回答
  •  无人及你
    2021-01-16 00:06

    This is how I used Swagger with JWT Authentication:

    • Write a Express.js API end point to generate a JWT.
    • Create a Swagger Path to retrieve the JWT using above end point
    • In swagger.yaml root level:

      securityDefinitions:  
        JWT:  
          type: apiKey  
          in: header  
          name: access_token  
      
    • In swagger.yaml paths:

      security  
       -JWT: []
      

    This will display an Authorize button in Swagger UI on browser.

    • Enter JWT generated above in the Authentication Window that pops-up when above Authorize button is clicked
    • Now JWT will be passed with the request headers

    Hope this may help others.

提交回复
热议问题