登录 Webtest Oauth2 [英] Sign in Webtest Oauth2

查看:34
本文介绍了登录 Webtest Oauth2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用完整的 VS Enterprise 对我们的 WebApplication 进行一些负载测试,我正在努力创建一个有效的 webtest.我们测试的站点是带有 AAD 身份验证前端的 Azure WebApp/API.失败的是作为测试用户的身份验证.使用 VS 或 fiddler 录制时,我无法再次播放测试.我相信这是凭据/令牌问题...

Using a full VS Enterprise to do some load testing against our WebApplication, I am struggling to create a webtest that works. Our tested site is an Azure WebApp/API with an AAD authentication frontend. It is the authenticating as a test user that is failing. While recording with VS or fiddler, I'm failing to playback the test again. I believe it is a credentials/token issue...

由于我们的应用程序不是本机应用程序,因此我无法获得特定用户凭据的令牌.(我得到一个已知的例外)我已经通过使用下面的代码创建插件及其 PreWebtest 方法成功获得了不记名令牌,但这是在应用程序而不是特定用户级别.

As our app is not a Native one, I cannot get a token for a specific users credentials. (I'm getting a known exception) I have succeeded in getting a Bearer token via the creation of a plugin and its PreWebtest method utilizing the code below however this is at application rather than specific user level.

private string GetAdToken(string inClientId, string inAppKey, string 
inAadInstance, string inTenant, string inToDoResourceId)
{
// inToDoResourceId = https://graph.microsoft.com
var myCredential = new ClientCredential(inClientId, inAppKey);
string myAuthority = string.Format(CultureInfo.InvariantCulture, 
inAadInstance, inTenant);
var myAuthContext = new AuthenticationContext(myAuthority);
Task<AuthenticationResult> myResults = 
myAuthContext.AcquireTokenAsync(inToDoResourceId, myCredential);
return myResults.Result.AccessToken;
}

如何针对特定的 AAD 测试用户身份实现自动化(通过 Web 测试),以便进一步测试我们的 Web 应用程序的自动化?提前致谢,

How can I achieve automation (via the web test) against a specific AAD test user identity to allow further testing automation of our web application? Thanks in advance,

推荐答案

感谢您的回答.我找到了解决我的问题的方法:VS webtest 工具中有一个设置凭据"按钮,您可以在其中添加凭据.当我再次运行测试时,测试成功登录到我的网络应用程序.

Thanks for your answers. I found a solution to my problem: there is a "Set Credentials" button in VS webtest tool where you can add your credentials. when i ran my test again, the test succeeded to sign in to my webapp.

@GuillaumeLaHaye,是的,我知道我的 AcquireTokenAsync() 方法不是特定于用户的,但是当我使用带有 UserCredential 的方法时,我收到此异常:请求正文必须包含以下参数:client_secret 或 client_assertion".

@GuillaumeLaHaye, Yes I know that my AcquireTokenAsync() method was not user-specific but when Im using the one with UserCredential I was getting this exception: The request body must contain the following parameter: 'client_secret or client_assertion'.

因为它是 WebbApp/API 而不是本机应用程序(在 Azure 门户中配置,参见 ADAL:请求正文必须包含以下参数:client_secret)

because it is a WebbApp/API and not a Native App (configured in Azure Portal, cf. ADAL: The request body must contain the following parameter: client_secret)

@AdrianHHH,在 preWebtest 方法(在每次测试之前运行)的 pugin 中调用了 Get Ad 令牌,其中包含我的 Web 应用程序的 clientId、clientSecret、tenantId、AadInstance(我在我的 azure 门户上找到了它们)...来自这个 Oauth 2.0 流程,我相信我想获得授权代码或访问令牌,但是因为我是网络测试和授权流程的新手,我真的不知道我得到了哪个令牌,也不知道如何使用它......

@AdrianHHH, Get Ad token was called in a pugin in the preWebtest method (running before every test) with the clientId, clientSecret, tenantId, AadInstance of my web App (I found them on my azure portal)... From this Oauth 2.0 flow, I believe I wanted to get the Authorization code or the access token, but because i'm new in webtesting and Authorization flow, I don't really know which token i got, neither how to use it...

Oauth2.0 流程

这篇关于登录 Webtest Oauth2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆