Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

109
Vistas
How to handle a Bearer token in K6

As the title implies, as of now I'm facing some "doubts" regarding the Authorization with Bearer Token using K6 given that I'm receiving that Token as access_token from a getAuth method/service, right now I have the following:

getAuthtoken.js

import http from 'k6/http';
import { check, sleep } from "k6";
import * as general_data from '../utility/general.js';
import * as auth_data from '../utility/authentication.js';

export default function () {
  var url = `${general_data.baseUrl}${auth_data.url}`;
  var payload = JSON.stringify(auth_data.body);

  const headers = {
    headers: auth_data.headers,
};
  const res = http.post(url, payload, headers);
  check(res, {
      'status was 200': r => r.status == 200,
  })
  console.log(res.body)
  return res.json()
}

The Json response looks like this:

{
    "access_token": "vHS9awrfrzTWxMGpAsVNWD2aSsKXkoGBZg8RgCSoQDo",
    "token_type": "Bearer",
    "expires_in": 900,
    "refresh_token": "f2SxXA0Nbr-OXE8RlVonej3xaKc-zifO4ZVMcGIGTAM",
    "scope": "public",
    "created_at": 1643633573
}

So I need to somehow grab this access_token and the token type bearer in order to be able to use it in another .js file and consume each and every API method, for example, use it in this script:

getWorkflowsRampUp.js

import http from 'k6/http';
import { check, sleep } from "k6";
import * as general_data from '../utility/general.js';
import * as auth_data from '../utility/authentication.js';
import * as workflows_data from '../utility/workflows.js';

export let options = {
    stages: [
        { duration: "10s", target: 2 }, 
        { duration: "20s", target: 5 },      
        { duration: "5s", target: 0 }
    ]
  };

export default function () {
  var url = `${general_data.baseUrl}${workflows_data.url}`
  var payload = JSON.stringify(auth_data.body);
  const res = http.get(url, payload, {
    headers: auth_data.headers
    }
  );
  check(res, {
      'status was 200': r => r.status == 200
  })
  console.log(res.body)
  sleep(1);

}

Any guidance would be greatly appreciated since I haven't been able to find any specific information or guide in doing these even bought some Udemy courses and didn't even come close to this scenario :(

Thanks in advance as always guys and have a nice week!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda