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