以特定用户身份查询 AAD 图 API
Query the AAD Graph API as a specific user
- 我有一个 webapi,服务正在代表用户调用它。
- 我有用户 ID,但没有他们的授权令牌。
我的 objective 以检查此用户是否属于指定组。
- 我有一个应用程序,可以根据图表进行身份验证,购买我的声明受我的组织限制,因此我无法查询用户。
- 我创建了一个应该可以访问图表的服务帐户 API。
- 我正在处理这个例子:https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/blob/master/GraphConsoleAppV3/AuthenticationHelper.cs
我正在尝试使用服务帐户连接到图表,但我不确定如何连接。我试过查看 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}
- 我有一个 webapi,服务正在代表用户调用它。
- 我有用户 ID,但没有他们的授权令牌。
我的 objective 以检查此用户是否属于指定组。
- 我有一个应用程序,可以根据图表进行身份验证,购买我的声明受我的组织限制,因此我无法查询用户。
- 我创建了一个应该可以访问图表的服务帐户 API。
- 我正在处理这个例子:https://github.com/Azure-Samples/active-directory-dotnet-graphapi-console/blob/master/GraphConsoleAppV3/AuthenticationHelper.cs
我正在尝试使用服务帐户连接到图表,但我不确定如何连接。我试过查看 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}