K6 & AUTH 0 (429 error) with k6 load tests

Hi @dmwprofessionnel !

Welcome to the community forums! :wave:

There are several approaches to doing this. It depends on your use case.

The one could be generating the access token in a setup (Test lifecycle) like suggested in the Generate access token by using refresh token - #5 by Purin

The other possible way if you need to authorize multiple VUs is to use & store the token in the variables, e.g.:


let token = '';

export default () =>  {
  // check and if needed generate token
  // also check if token is not expired
  if (!token) {
    token = 'token for VU ' + __VU;
    console.log('VU: ' + __VU  + ', iter: ' + __ITER  + ', generated token: ' + token);  
  } else {
    console.log('VU: ' + __VU  + ', iter: ' + __ITER  + ', re-use token: ' + token);
  }

  // do something with the token
}

Hope that answers,
Cheers!

1 Like