如何验证和创建推送通知订阅以获取Outlook电子邮件@mentions?

时间:2018-11-14 07:38:26

标签: outlook microsoft-graph azure-ad-graph-api outlook-restapi

我正在尝试进行身份验证,以便使用Outlook REST API通过“推送订阅”订阅Outlook电子邮件。我正在使用此文档作为参考:https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/notify-rest-operations

我在portal.azure.com中创建了一个应用,并在“ Office 365 Exchange Online” API下提供了“读取用户邮件”所需的权限。

Grant Required permission of Read user mail Screenshot

我正在使用以下代码使用“ Microsoft.Identity.Client” nuget包来获取Bearer令牌。但是我仍然无法订阅Outlook Push Notification REST API,并且出现401未经授权错误。

  static async Task<AuthenticationResult> AuthorizeAsync(string clientId)
    {
        var authority = $"https://login.microsoftonline.com/{tenantName}.onmicrosoft.com";
        var app = new PublicClientApplication(clientId, authority);
        string[] scopes = new string[] { "Mail.Read" };
        var accounts = await app.GetAccountsAsync();

        AuthenticationResult authenticationResult = null;
        if (accounts.Any())
        {
            authenticationResult = await app.AcquireTokenSilentAsync(scopes, accounts.FirstOrDefault());
        }
        else
        {
            try
            {
                var username = $"{Environment.UserName}@microsoft.com";
                authenticationResult = await app.AcquireTokenByIntegratedWindowsAuthAsync(scopes, username);
            }

有人在类似问题上进行过身份验证和创建“推送通知订阅”以获取Outlook电子邮件,请提供帮助吗?

0 个答案:

没有答案