【发布时间】:2017-11-13 15:03:17
【问题描述】:
我们有一个要求,我们需要使用委托访问代表该用户向用户 Outlook 帐户添加约会。所有邮件都在同一个域或同一个网络中。我们正在尝试通过将 Oauth 与 office365 结合使用,创建 Azure 应用程序并提供应用程序级别的“日历读取和写入”委托权限。 我已将 https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service-apps-with-office-365-mail-calendar-and-contacts-apis-oauth2-client-credential-flow/ 文章引用到设置 azure 应用程序,它将为我提供访问令牌。 在获取访问令牌时,我使用了以下代码
private static string GetTokenUsingCertificate()
{
string authority = string.Format("https://login.windows.net/{0}/oauth2/authorize", tenantID); ;
string outlookUri = "https://outlook.office365.com/";
var authenticationContext = new AuthenticationContext(authority, false);
var clientCertificate = new ClientAssertionCertificate(clientId, GetClientCertificate());
AuthenticationResult authenticationResult = null;
try
{
authenticationResult = authenticationContext.AcquireTokenAsync(outlookUri, clientCertificate).Result;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return authenticationResult?.AccessToken;
}
上述功能为我提供访问令牌,但当我尝试使用 Exchnage 服务向用户 Outlook 日历添加约会时,我收到“令牌不包含权限,或权限无法理解”。例外。 添加约会时,我使用以下代码
private void AddAppointment()
{
ExchangeService exchangeService = new ExchangeService();
exchangeService.Credentials = new OAuthCredentials(accessToken);
exchangeService.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
Appointment appointment = new Appointment(service)
{
Subject = "EWS OAuth: Appointment 2",
Body = "EWS OAuth Auth: Body",
Start = DateTime.Now.AddMinutes(10)
};
appointment.Save(
new FolderId(WellKnownFolderName.Calendar, new Mailbox("mail@outlook.com/")),
SendInvitationsMode.SendToNone);
}
请帮我解决这个问题。
块引用
【问题讨论】:
标签: azure oauth outlook exchangewebservices