繁体   English   中英

以编程方式登录Azure Active Directory

[英]Login to Azure Active Directory programmatically

我有一个在Azure Active Directory中注册的站点(app)。 我需要我的Web测试在开始时对自己进行身份验证(使用预先存在的测试用户),以获取用于测试的auth令牌以命中受保护的API。

在C#中实现这一目标的最佳方法是什么?

您可以尝试执行以下操作:

var authContext = new AuthenticationContext("https://login.microsoftonline.com/{tenantid}")
    UserCredential userCredential = new UserCredential(userName, password);
    AuthenticationResult authResult = authContext.AcquireToken("https://graph.windows.net/", clientId, userCredential);

其中userNamepassword是测试用户的用户名和密码。 authResult有一个名为AccessToken的成员,可以将其传递给您要测试的方法。

暂无
暂无

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

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