以特定用户身份查询 AAD 图 API

Query the AAD Graph API as a specific user

我的 objective 以检查此用户是否属于指定组。

我正在尝试使用服务帐户连接到图表,但我不确定如何连接。我试过查看 UserPasswordCredential,但 AcquireTokenAsync 没有将其作为参数,但确实需要 UserAssertion 我在查找有关正确构造该对象的文档时遇到了麻烦。

如有任何帮助,我们将不胜感激。

如果您使用 .Net Framework 进行开发,AcquireTokenAsync 会提供使用 UserPasswordCredential 的方法。

下面是供您参考的代码示例:

AuthenticationContext authenticationContext = new AuthenticationContext(UserModeConstants.AuthString, false);
string resrouce = "";
string clientId = "";
string userName = "";
string password = "";
UserPasswordCredential userPasswordCredential = new UserPasswordCredential(userName, password);
var token= authenticationContext.AcquireTokenAsync(resrouce, clientId, userPasswordCredential).Result.AccessToken;

我正在使用 3.13.5.907 Microsoft.IdentityModel.Clients.ActiveDirectory 版本。而且此方法仅适用于您在 Azure AD 上注册的本机客户端应用程序,因为它不提供凭据。如果你想让它在网络上工作 application/web API,你可以像下面这样直接发出 HTTP 请求:

POST: https://login.microsoftonline.com/xxxxx.onmicrosoft.com/oauth2/token

Content-Type: application/x-www-form-urlencoded
resource={resource}&client_id={clientId}&grant_type=password&username={userName}&password={password}&scope=openid&client_secret={clientSecret}