【问题标题】:Facing "The token contains no permissions, or permissions can not be understood." issue in EWS with Oauth面对“令牌不包含权限,或权限无法理解”。 EWS 中的 Oauth 问题
【发布时间】: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


    【解决方案1】:

    EWS 不允许与 REST API 允许的相同级别的 OAuth 权限范围(或权限限制),这是使用 REST 与 EWS 的一大优势。如果您有 Office365,为什么要尝试通过 REST 使用 EWS?

    回答你需要的问题

    EWS 的 OAuth 身份验证仅在 Exchange 中作为 Office 365 的一部分提供。EWS 应用程序需要“完全访问用户邮箱”权限。

    根据https://msdn.microsoft.com/en-us/library/office/dn903761%28v=exchg.150%29.aspx

    【讨论】:

    • 我们正在使用 EWS,因为根据我们的要求,我们需要支持 On-Premise 和 Office365 邮箱。而 REST 只支持 office365 邮箱,另外我们需要使用 EWS Eisner 功能。那么有没有办法通过特定的委托访问(日历读取、写入)而不是“完全访问用户邮箱”来支持 OAuth?
    • 没有 EWS 需要完全访问权限
    猜你喜欢
    • 2020-06-19
    • 2019-06-11
    • 1970-01-01
    • 2016-09-29
    • 1970-01-01
    • 2016-10-09
    • 2015-01-09
    • 2016-08-11
    • 1970-01-01
    相关资源
    最近更新 更多