简体   繁体   English

Jmeter - Azure AD - Bearer Token - 配置函数

[英]Jmeter - Azure AD - Bearer Token - Configuration Function

I have created a plugin in Visual Studio that uses the following classes:我在 Visual Studio 中创建了一个使用以下类的插件:

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.此类使用客户端 ID、客户端密码和资源 ID 来输出不记名令牌,该不记名令牌附加到请求的标头,以提供对 Azure 中应用程序的性能测试访问。

However, we are now looking to move over to use JMeter.但是,我们现在正在寻求转而使用 JMeter。 The goal was to create the same function in JMeter.目标是在 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.但是,它似乎并不能完全满足我在使用所需变量方面的需求,请逐步执行配置令牌的 Microsoft 配置。

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#.这是在 Visual Studio 中使用 C# 生成 {token} 的代码。

What classes and functions do I need to use within JMeter in order to output the same value?为了输出相同的值,我需要在 JMeter 中使用哪些类和函数?

Sod's law...I was able to get the script running. Sod's law...我能够让脚本运行。 The following link was helpful: https://swtestacademy.com/jmeter-tutorial-api-performance-testing .以下链接很有帮助: 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:第一个 HTTP 请求需要遵循以下内容:

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

Add the variables: - grant_type - client_id - client_secret - resource添加变量: grant_type - client_id - client_secret - resource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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