Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda