我是Azure AD的新用戶,並嘗試使用AD保護的api。我已經成功創建並保護了api,但在Windows窗體應用程序中耗費時間。我曾嘗試在文檔Link,但在這一行Azure AD從認證結果對象獲取訪問令牌
AuthenticationResult ar =
ac.AcquireToken("https://cloudidentity.net/WindowsAzureADWebAPITest",
"a4836f83-0f69-48ed-aa2b-88d0aed69652",
new Uri("https://cloudidentity.net/myWebAPItestclient"));
得到一個編譯時錯誤有一個在ADAL沒有這樣的方法了。還有就是我試圖異步版本,但採用不同的參數
AuthenticationResult ar =
ac.AcquireTokenAsync("https://cloudidentity.net/WindowsAzureADWebAPITest",
"a4836f83-0f69-48ed-aa2b-88d0aed69652",
new Uri("https://cloudidentity.net/myWebAPItestclient"), IPlatformParameters);
隨着其他信息,同時也希望IPlatformParameters對象,這我不知道的想法。我試圖通過空,繼續前進,但隨後出現的錯誤在這行
string authHeader = ar.CreateAuthorizationHeader();
錯誤是存在ADAL爲AR對象沒有這樣的方法。所以我跳到這 tutorial,因爲他也使用Windows窗體應用程序。他寫的代碼是
Task<AuthenticationResult> ar = authContext.AcquireTokenAsync("https://carsforher.onmicrosoft.com/SecuredCars_20160722021100", "2640aca3-a35e-42f8-8f6d-2e5fe1a09df4", new Uri("http://localhost"), null);
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ar.AccessToken).....
但是沒有屬性作爲ar對象的AccessToken。然後我試着從Azure Documentation下載示例應用程序,但他們也寫了完全相同的代碼,但不幸的是這些代碼不起作用。我使用的ADAL版本是3.12.0.827。請幫助我弄清楚如何獲取訪問令牌並使用API。