c# - 使用 GraphServiceClient 查询 Azure AD
问题描述
我想使用 GraphServiceClient 为用户查询 Azure Active Directory。
我在 Azure 门户上注册了一个应用程序并取回了一个令牌。现在我想获取我的 ActiveDirectory 的用户,但不明白如何查询 Azure AD
static async void Works() //gets a token
{
try
{
var tenantId = "myTenant";
var clientId = "myId";
var clientSecret = @"MySecret";
// Configure app builder
var authority = $"https://login.microsoftonline.com/{tenantId}";
var app = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecret)
.WithAuthority(new Uri(authority))
.Build();
// Acquire tokens for Graph API
var scopes = new[] { "https://graph.microsoft.com/.default" };
var authenticationResult = await app.AcquireTokenForClient(scopes).ExecuteAsync();
// Create GraphClient and attach auth header to all request (acquired on previous step)
var graphClient = new GraphServiceClient(
new DelegateAuthenticationProvider(requestMessage =>
{
requestMessage.Headers.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", authenticationResult.AccessToken);
return Task.FromResult(0);
}));
// Call Graph API
//HOW DO I QUERY AZURE AD????
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
}
解决方案
推荐阅读
- jquery - 如何使用jquery连续旋转图像
- javascript - 如何在角度 6 中显示多个行值的总数以分隔表格的列?
- reactjs - React 没有将状态传递给 mapStateToProps
- c# - 循环后是否需要调用`yield break`?
- r - 如何避免用户定义函数的命名空间歧义
- tensorflow - 如何在 TPU 上实现布尔屏蔽
- python - 我现在应该怎么做才能解决这个问题,因为它显示 x 未定义?
- android - 如何从 webview 中的存储访问 IndexedDB?
- python - Python Tkinter“exportselection”在 Windows 机器上不起作用
- python - 获取列表中最小项的索引