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

How to use swagger with authentication JWT? #14

Open
miguelortizdev opened this issue Mar 19, 2019 · 2 comments
Open

How to use swagger with authentication JWT? #14

miguelortizdev opened this issue Mar 19, 2019 · 2 comments

Comments

@miguelortizdev
Copy link

how to configure swagger with JWT to make requests with a token?

@AndersonGuilherme
Copy link

how to configure swagger with JWT to make requests with a token?

@crbast
Copy link

crbast commented Jun 25, 2019

Hey👋🏼,
I have a functional solution but not perfect:

  1. Add this code in config/swagger.js in the securityDefinitions section.
bearerAuth: {
   type: 'apiKey',
   in: 'header',
   name: 'Authorization'
},
  1. In the same file add this code to the options section.
securitySchemes: {
   bearerAuth: {
      type: 'http',
      scheme: 'bearer',
      bearerFormat: 'JWT'
   }
},

PS : You can change bearerAuth by JWT

  1. Add a new security element to your documentation.
    ex:
* /api/auth:
*  post:
*      tags:
*          - Auth
*      security:
*          - bearerAuth: []
*      summary: Auth JWT login
*      . . .
  1. In swagger : Before the token add Bearer. Ex: Bearer <your-token>

image

Have a nice day!

swagger.zip -> full file config/swagger.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants