简体   繁体   中英

Jmeter - Azure AD - Bearer Token - Configuration Function

I have created a plugin in Visual Studio that uses the following classes:

using Microsoft.Azure.KeyVault;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.AzureKeyVault;

This classes use the Client ID, Client Secret and Resource ID to output a bearer token, which is appended to a header of a request to provide performance testing access to an application sitting in Azure.

However, we are now looking to move over to use JMeter. The goal was to create the same function in JMeter.

I have looked on various forums and sites. However, it doesn't seem to cater exactly for what I am looking for in terms of using the variables required, step through the Microsoft configuration which configures the token.

public string TenantId = "{TenantID}";
public string Authority = "{Authority URL}";

private static IConfiguration Configuration;
private ApplicationAuthenticator _applicationAuthenticator;

public override void PreWebTest(object sender, PreWebTestEventArgs e)
    {
        Configuration = 
TestConfigurationBuilder.BuildConfiguration(KeyVaultUrl, AppId, TenantId, 
AppKey, Authority);

        _applicationAuthenticator = new 
ApplicationAuthenticator(Authority);
        string token = 
_applicationAuthenticator.SetToken
(Configuration[ClientIdKeyVaultVariable], 
Configuration[ClientSecretKeyVaultVariable], 
Configuration[ResourceIdKeyVaultVariable]);

        e.WebTest.Context.Add("AuthToken", $"Bearer {token}");
    }

This is the code that generates the {token} in Visual Studio using C#.

What classes and functions do I need to use within JMeter in order to output the same value?

Sod's law...I was able to get the script running. The following link was helpful: https://swtestacademy.com/jmeter-tutorial-api-performance-testing .

It was simpler than I thought. The first HTTP request needs to be along the lines of:

login.microsoftonline.com/{company specific}/oauth2/token?= 

Add the variables: - grant_type - client_id - client_secret - resource

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM