我是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。