swagger-jwt-example
swagger-jwt-example copied to clipboard
Swagger and JWT using Node.js
Swagger JWT Example
Minimal working example of how to integrate JWT with Swagger using Node.js. You can read the full post on my blog: http://miguelduarte.pt/2017/04/19/using-jwt-authentication-with-swagger-and-node-js/
How to run this
-
Start the server by running
npm start
-
Check the swagger-ui on
http://localhost:3000/docs
-
GET
http://localhost:3000/api/unprotected
should work -
GET
http://localhost:3000/api/protected
should NOT work -
POST
http://localhost:3000/api/login/user
with the following body{ "username": "username", "password": "password" }
and take the token that you get in the response -
GET
http://localhost:3000/api/protected
again with the following headerAuthorization: Bearer _TOKEN_
, replacing_TOKEN_
with the value you got from request #4
Then you can try logging in as an admin and accessing the admin-only route.