Azure B2C and k6 Browser Testing

Hey, I’m running into a bit of a snag while using k6 browser for testing my web app, which uses Azure B2C for authentication.

Here’s the issue: Unlike typical login forms where you just enter an email and password, Azure B2C requires an access token to be used as a cookie for authentication. I’ve tried several methods to get this access token as a cookie in k6 browser, but nothing seems to work as expected.

To make things even more confusing, I’ve also tried using an HTTP request to fetch an access token from one of my app’s endpoints, and I did get a 200 response with a new valid token. However, even with a valid token in the cookie jar, I still can’t navigate the app using k6 browser. It seems like the browser isn’t recognizing the cookie for authentication.

If anyone has experience or tips on using OAuth2 and Azure B2C with k6 browser, or if you know of alternative methods to tackle this issue, your advice would be greatly appreciated.

Thanks in advance

I am also having the same issue (also trying to inject the cookie with the azure token ). Does this happen to you with both (cookiejar and addCookies)? Cookie jar is exclusive for k6/http client (api) and addCookies is exclusive for the http browser client , you can try both

Hi @bbayrkdar1,

Welcome to the forum!

Could you please tell us the k6 version you’re using? It would be great if you could share with us a script snippet.

Thanks.

1 Like

Hi,

I’m using k6 version 0.46.0. Here’s a snippet of couple of the functions I tried to use.
But none of them seem to work as expected.

regards,

Hi @bbayrkdar1,

It seems like you’re using an older version. Please upgrade your k6 to version 0.47.0 for improved cookie support.

Adding cookies using the browser module API and then using them with another module (http) isn’t supported. Using only a single module API would be best.

  • Here are more details if you want to use the http module: Cookies.
  • Here are more details for using the browser API to manage cookies: addCookies(). Please check out the example at this link.

Hope this helps.

1 Like

Hi @inancgumus

I meant to convey that I don’t use both methods simultaneously, but in a snap, I was just showing all the ones I’ve used.
Even after updating to version 0.47.0, I’m still facing the same issue.

regards,

I see. Then, if you want to use the browser module, it would be best to update your k6 version to 0.47.0. It’s because we made improvements to our cookie API. Thanks!

Hi @inancgumus

Thank you for your message! I appreciate your assistance. I’ve indeed tried with the new update, but unfortunately, the issue seems to remain the same. The redirect isn’t working as expected. I even attempted to navigate explicitly, but then I noticed that the cookie doesn’t seem to have been added.

When I check the browser to see what cookies are there, I can’t find it as expected. Instead, I observed that there are 3 cookies with names like xs-m and such, which I didn’t add myself.

Do you have any idea why these cookies are appearing and how I can resolve the issue? Any help is greatly appreciated!

Hi @bbayrkdar1,

Happy to help! To resolve the issue and help you further, I need a simple test script code to run locally and reproduce the issue.

Thanks.