Azure AD 应用注册 - Exchange API - 读取日历



我在 Azure AD 应用中授予了以下权限:

应用程序:

Read calendars in all mailboxes
Read and write calendars in all mailboxes
Read calendars in all mailboxes

委托:

Read user and shared calendars
Read and write user and shared calendars
Read and write user calendars
Read user calendars
Read and write user and shared calendars
Read user and shared calendars

注册屏幕截图

我已成功生成如下所示的访问令牌:

const string clientId = "my-client-id";
const string clientSecret = "my-secret"; // C
var tenant = "mytenant.onmicrosoft.com";
var authContext = new AuthenticationContext($"https://login.windows.net/{tenant}/oauth2/token");
var credentials = new ClientCredential(clientId, clientSecret);
AuthenticationResult authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", credentials);

使用该访问令牌,我正在尝试向传递持有者令牌标头/CalendarView发出基本请求:

https://outlook.office.com/api/v2.0/users/my@email.com/calendarview?startDateTime=2017-11-12&endDateTime=2017-11-13

但是,我一直收到Access Denied.我是否需要设置其他权限?我是否调用了正确的终结点?

您不包括错误响应的正文,但我的猜测是,您之所以遇到此问题,是因为 Exchange 不接受使用共享密钥生成的令牌。相反,您需要使用基于证书的断言来请求令牌。Azure 在此处将此记录为"第二种情况:使用证书的访问令牌请求"。

我实际上能够弄清楚这一点。我没有使用 Exchange API,而只是在图形 API 中应用了权限。

命中以下端点:

https://graph.microsoft.com/v1.0/users/{email}/calendarview?startDateTime={startDate}&endDateTime={endDate}

目前还不清楚使用哪个 API 之间的区别......但我现在正在前进。