Using JMeter With OAuth

Had an interesting battle with JMeter recently. I needed to load test on an authorized endpoint. I’m no expert on JMeter but I have a basic understanding. It didn’t look like retaining a token from an auth request was easily supported in JMeter. So here’s how I did it…..

Getting and Abstracting the Token

I added a new http request to my Test Plan

This request calls the token endpoint with the necessary client_id, secret, scopes etc. As standard the response returns the bearer token. I was able to then parse the token into a variable via the Json Extractor

As you can see in the screenshot above I’ve extracted the access_token into a bearerToken variable. Using the Http Header Manager I’m now able to include the token in subsequent requests.

This worked rather well. The only problem I had now is that for the actual authorized request I want to load test I didn’t want to include the token request. I struggled with how I could handle this then I noticed the “Once Only Controller”….

As you can see in the screenshot above the Once Only Controller contains the token request. All load test runs, loops etc now only run the token once then subsequent load test end points are executed as standard.

Leave a Reply