generated from alkemyTech/base-ong-server-java
-
Notifications
You must be signed in to change notification settings - Fork 0
JWT Postman config
Diego Martinez Giardini edited this page Nov 29, 2021
·
2 revisions
- Levantar el código en el IDE.
- Abrir Postman y crear una nueva Collection.
- Crear un POST request con url http://localhost:8080/authenticate (Ruta de ejemplo, se debe reemplazar "authenticate" por la ruta expresada en el controller, en este caso, en nuestro método POST).
- Nos dirigimos a los Headers y agregamos lo siguiente:
KEY = Content-Type VALUE = application/json
- Abrimos la pestaña Body y dentro de ella escribimos el username y password en formato json, del siguiente modo: { "username":"username", "password":"password" }
- Ejecutamos y obtendremos de respuesta un JWT.
- Copiamos el JWT y creamos una una nueva request, en este caso un GET request con la url http://localhost:8080/hello (Ruta de ejemplo, se debe reemplazar "hello" por la ruta expresada en el RequestMapping del controller).
- Nos dirigimos a los Headers y agregamos lo siguiente:
KEY = Authorization VALUE = Bearer xxx ("xxx" representa el JWT obtenido previamente)
- Ejecutamos y deberíamos ver el mensaje retornado.
<-------------- English --------------->
- Run the code in the IDE.
- Open Postman and create a new Collection.
- Create a POST request with url http: // localhost: 8080 / authenticate (Example path, "authenticate" must be replaced by the path expressed in the controller, in this case, the one in our POST method).
- Go to the Headers tab and add the following:
KEY = Content-Type VALUE = application / json
- Open the Body tab -> Change to RAW and then set JSON type. Inside the body we should write the username and password in json format, as follows: { "username": "username", "password": "password" }
- Execute and you will get a JWT as response.
- Copy the JWT and create a new request, in this case a GET request with the url http://localhost:8080/hello (Example path, "hello" must be replaced by the path expressed in the controller RequestMapping ).
- Go to the Headers tab and add the following:
KEY = Authorization VALUE = Bearer xxx ("xxx" represents the JWT obtained previously)
- Execute and you should see the returned message and a 200 HTTP Response.