【发布时间】:2015-04-15 12:53:18
【问题描述】:
我正在尝试使用 ADAL 库访问 Office365 REST API,但得到 401(未经授权),但不知道原因。我已经在我们的 Azure AD 中注册了一个应用程序,获得了一个 ID,为它获取了一个密钥,并授予它读取 Windows Azure Active Directory 的权限。
我能够获取 OAuth 令牌,但它无法与 Office365 API 一起使用。
这是我失败的尝试之一:
AuthenticationContext auth = new AuthenticationContext("https://login.windows.net/" + myTenant);
AuthenticationResult authenticationResult = auth.AcquireToken("http://Rest", new ClientCredential(myId, myKey));
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authenticationResult.AccessToken);
HttpResponseMessage msg = await client.GetAsync("https://outlook.office365.com/api/v1.0/me/events");
// => Bam. 401. :(
有什么想法吗?
【问题讨论】:
标签: office365 adal outlook-restapi