Colin
Colin

Reputation: 174

Visual studio Web Performance tests - OAuth 2.0

I am trying to create the Web Performance tests for an app that is using Identity Server 3. I can't figure out how to simulate login and get token.

For example, I am using myapp.com and identity server is hosted on identity.com. All my endpoints in myapp.com/api are secured and require Bearer token. identity.com can provide me token in exchange for a username and password. identity.com will redirect me to a myapp.com/tokenRedirect?token=***. How can I catch the token and use it as an Authorization header for API requests?

There are some solutions for JMeter but could not find any for VS 2017 tests.

Upvotes: 0

Views: 868

Answers (1)

AdrianHHH
AdrianHHH

Reputation: 14038

Redirections are handled automatically, by default, in a test recorded by Visual Studio and hence the redirection response containing the token is not accessible. Setting the FollowRedirects property of the request to False allows the response containing the redirection to be accessed by the usual extraction rules and/or plugins etc. One of them can be used to find the token value and save it to a context parameter (CP). Having turned off the automatic redirection handling, a new request should be added (use the Insert request command, do not use Add dependent request) and it should have the request that the redirection wants. Hence its url should be of the form myapp.com/tokenRedirect?token={{TheCPWithTheToken}}.

In later requests the CP with the token can be added via the Add header command, or an existing header field can be modified to use the CP.

Upvotes: 2

Related Questions