API load test using OAuth2.0 authentication

3,477 views
Skip to first unread message

Jignesh Mithapara

unread,
Dec 26, 2016, 1:50:25 AM12/26/16
to jmeter-plugins
Hello,

We have few APIs which are secured with OAuth2.0 security. We are using postman to generate token using OAuth 2.0. We generate token using "Access Token URL", "Client ID", "Client Secret" and "Grant Type=Client Credentials" in the postman and use this token into API.

Now, we want to perform load test for these APIs using apache JMeter 3.1. For that, we need to generate token with different users and we need to use these tokens in the APIs.

I searched on web but I didn't found any proper solution. we have OAuth sampler but it is using OAuth1.0.

So, can somebody tell me how can I perform load test using OAuth2.0 authentication in JMeter ?

Thanks in advance..
Message has been deleted

Jignesh Mithapara

unread,
Feb 22, 2017, 3:29:45 AM2/22/17
to jmeter-plugins
Now, it is working fine for me.

Solution: 

Thread Group1:
Number of Threads: 1
Ramp-Up Period: 1
Loop Count: Forever
HTTP Request: 
Server Name or IP: 192.168.1.10
Protocol : https
Path: /xyz/oauth/token?grant_type=client_credentials
HTTP Authorization Manager: Setup credential for basic authentication
Username: OTH1
Password: OTH1
Mechanism: BASIC_DIGEST
Regular Expression Extractor: Extract token from the response
Reference Name: OTH1
Regular Expression: "access_token":"(.+?)"
Template: $1$
Match No.: 1
BeanShell PostProcessor: Send above extracted token into another Thread Group
Script : ${__setProperty(OTH1,${OTH1},)}; 

Thread Group2: Send request to API and retrieve response
Number of Threads: 10
Ramp-Up Period: 1
Loop Count: Forever
Startup delay (seconds): 5
HTTP Request: Send request to API
Server Name or IP: 192.168.1.11
Protocol : https
Path: <API>
Parameters:
Name: access_token
Value: ${__P(OTH1,)}

santhosh....@corporategovernancerisk.com

unread,
Aug 14, 2017, 2:51:17 AM8/14/17
to jmeter-plugins

Hi Jignesh Mithapara ,

Thanks for the solution and it worked for me .

I used Thread group 2 and got the API Response.

I liked to know what is the thread group 1 ?

Thanks
N.Santhosh

Jignesh Mithapara

unread,
Aug 14, 2017, 3:01:13 AM8/14/17
to jmeter-...@googlegroups.com

Thanks.

oauth2 has token to access any api. so we want to exract token from the response. Thread group 1 is used to exract this token from the response. This token will expire in 30-45 mins so we don't want to generate token every time. so we send this token to thread group 2 for accessing API...

Let me know if you have still any doubt..

Regards,
Jignesh

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugins+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

santhosh....@corporategovernancerisk.com

unread,
Aug 14, 2017, 3:06:58 AM8/14/17
to jmeter-plugins
I use Postman to generate a token and use this in my Jmeter.

So do you use Threadgroup1 to generate a tocken instead of postman ?

I am very new to Jmeter , so bit confused on this concept.

Jignesh Mithapara

unread,
Aug 14, 2017, 3:37:55 AM8/14/17
to jmeter-...@googlegroups.com

This code works with jmeter as you work with postman. This code definitly works.. Try it and let me know..

Sanjay Sharma

unread,
Sep 15, 2017, 9:29:57 AM9/15/17
to jmeter-plugins
HI Jagnesh,

Can you please let me know how we need to do OAUTH(1.0) API testing with Jmeter.

I stuck in the same from last 1 week.

Regards,
Sanjay



On Monday, 14 August 2017 10:37:55 UTC+3, Jignesh Mithapara wrote:

This code works with jmeter as you work with postman. This code definitly works.. Try it and let me know..

On 14-Aug-2017 12:37 PM, <santhosh....@corporategovernancerisk.com> wrote:
I use Postman to generate a token and use this in my Jmeter.

So do you use Threadgroup1 to generate a tocken instead of postman ?

I am very new to Jmeter , so bit confused on this concept.

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.

Jignesh Mithapara

unread,
Sep 15, 2017, 9:40:15 AM9/15/17
to jmeter-...@googlegroups.com

Hi,

If your application is using oauth1.0 then you can use oauth sampler.

To unsubscribe from this group and all its topics, send an email to jmeter-plugins+unsubscribe@googlegroups.com.

Jignesh Mithapara

unread,
Sep 15, 2017, 10:05:37 AM9/15/17
to jmeter-plugins
Hi Sanjay,

You can download this oauth sampler from https://jmeter-plugins.org/wiki/OAuthSampler/ site. 
It also describe you usecase of this sampler.

Sanjay Sharma

unread,
Sep 15, 2017, 10:23:43 AM9/15/17
to jmeter-...@googlegroups.com
I am using Jmeter 3.2 , I don't think oauth sampler is for this version.



--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugins+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Regards,
Sanjay Sharma
7503047766

Sanjay Sharma

unread,
Sep 15, 2017, 10:52:15 AM9/15/17
to jmeter-...@googlegroups.com
I have 4 values 

consumer key, consumer secret and token and token secret.

In OAUTH sampler we have provision to add only two values related with consume where I will add token values.

Regards,
Sanjay

On Fri, Sep 15, 2017 at 5:05 PM, Jignesh Mithapara <jignesh....@gmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugins+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jignesh Mithapara

unread,
Jan 3, 2018, 7:28:02 AM1/3/18
to jmeter-plugins
Hi Sanjay,

You can use OAuth1.0 sampler for your test. You just need to add consumer key, consumer secret and other necessary information in the sampler. You can't add manual token in any sampler due to session issue and Token will generate automatically. This token will use directly in your API. 

Thanks,
Jignesh Mithapara

On Friday, 15 September 2017 20:22:15 UTC+5:30, Sanjay Sharma wrote:
I have 4 values 

consumer key, consumer secret and token and token secret.

In OAUTH sampler we have provision to add only two values related with consume where I will add token values.

Regards,
Sanjay
On Fri, Sep 15, 2017 at 5:05 PM, Jignesh Mithapara <jignesh....@gmail.com> wrote:
Hi Sanjay,

You can download this oauth sampler from https://jmeter-plugins.org/wiki/OAuthSampler/ site. 
It also describe you usecase of this sampler.

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rohit Sachan

unread,
Jan 10, 2018, 7:23:41 AM1/10/18
to jmeter-plugins
Hi Jignesh,

I tried the below solution but not able to get the successful result. Can you please guide me more on it or share the .jmx file?

Best regards,
Rohit Sachan

Jignesh Mithapara

unread,
Jan 10, 2018, 7:27:51 AM1/10/18
to jmeter-...@googlegroups.com
Hi Rohit,

I already shared each and every jmx code  in above conversation.
Can you please share your .jmx file ? So, I will guide you in appropriate manner.

Regards,
Jignesh Mithapara

--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/OjrE7_sYDdg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugins+unsubscribe@googlegroups.com.

Minh Hiếu Hoàng

unread,
Jan 31, 2021, 11:54:12 PM1/31/21
to jmeter-plugins
Hi, I have the same problem can you help me Jignesh?

I have many parameter but don't know where to get them. And oauth2 using pkce.
Vào lúc 19:27:51 UTC+7 ngày Thứ Tư, 10 tháng 1, 2018, jignesh....@gmail.com đã viết:
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages