Last active
August 23, 2024 01:41
-
-
Save mnolascor/340393c900d9a794bd8154f3c97921de to your computer and use it in GitHub Desktop.
Pre-request para Postman para generar token
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var requestOptions = { | |
| url: 'http://jwtbuilder.jamiekurtz.com/tokens', // URL para obtener el token | |
| method: 'POST', // Método POST | |
| header: { | |
| 'Content-Type': 'application/json' // Tipo de contenido JSON | |
| }, | |
| body: { | |
| mode: 'raw', // Usa 'raw' para cuerpo en JSON | |
| raw: JSON.stringify({ | |
| "claims": { | |
| "iss": "Online JWT Builder", | |
| "iat": 1724369831, | |
| "exp": 1755905831, | |
| "aud": "www.example.com", | |
| "sub": "jrocket@example.com", | |
| "GivenName": "Johnny", | |
| "Surname": "Rocket", | |
| "Email": "jrocket@example.com", | |
| "Role": [ | |
| "Manager", | |
| "Project Administrator" | |
| ] | |
| }, | |
| "key": "qwertyuiopasdfghjklzxcvbnm123456", | |
| "alg": "HS256" | |
| }) | |
| } | |
| }; | |
| // Ejecutar la solicitud POST | |
| pm.sendRequest(requestOptions, function (err, res) { | |
| if (err) { | |
| console.log('Error al obtener el token:', err); | |
| } else { | |
| // Extraer el token de la respuesta JSON | |
| var tokenExtraido = res.json().token; | |
| console.log(tokenExtraido) | |
| // Guardar el token en una variable global | |
| pm.globals.set('TOKEN', tokenExtraido); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment