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

Hello,
I’m using k6 to perform API Load testing, each request should send a header with an access token, obtained with a request to auth0, so each iteration send a first request to autho (obtain token) and send a second request to get a list of products (service tested), so I’m blocked with auth0 429 error code to many requests, I need to pass token one time as an execution context feature for all the session ( like pytest) how can I do it please, I’m blocked , thanks a lot for your help :slight_smile:

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

Hi :slight_smile: It’s good thanks a lot for your help !

1 Like