0
我正在开发一个简单的c#控制台应用程序来查询Azure AD并获取给定用户的详细信息。我发现了许多有关查询天青AD的有用文章,但没有一篇符合我的目的。发布在GitHub上的示例代码太冗长且复杂,因为我的简单需求。 我使用下面的代码,但我得到一个令牌错误:使用c#控制台应用程序查询Azure AD
static async void MakeRequest()
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
/* OAuth2 is required to access this API. For more information visit:
https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks */
// Specify values for the following required parameters
queryString["api-version"] = "1.6";
// Specify values for path parameters (shown as {...})
// var uri = "https://graph.windows.net/microsoft.onmicrosoft.com/users/{[email protected]}?" + queryString;
var uri = "https://graph.windows.net/72f988bf-86f1-41af-91ab-2d7cd011db47/users?api-version=1.6";
var response = await client.GetAsync(uri);
if (response.Content != null)
{
var responseString = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseString);
}
}
我进一步搜索的令牌访问和注册我的应用程序中的广告,并用下面的代码:
var authContext = new AuthenticationContext("AUTHORITY");
string token;
try
{
//var authresult = authContext.AcquireToken("MYAPP_ID", "MYAPP_CLIENTID", "MYAPP_REDIRECTURI");
var authresult = authContext.AcquireToken("https://graph.windows.net", "23b1c65e-5a20-4b88-a474-85c0845782c7", "https://localhost/");
token = authresult.AccessToken;
}
catch(Exception ex)
{
Console.WriteLine(ex);
}
但不是获得所需的结果。请帮忙!!!
应用程序ID是clientid。 –
此外代码显示PlatformParameters上的构建错误和用户的令牌 – dotnetman
我是否需要platformParamerters的任何程序集引用? – dotnetman