限制 Office365 App "Read mail in All mailboxes" 对特定邮箱的权限

Restrict Office365 App "Read mail in All mailboxes" permission to specific mailbox

我正在尝试通过 MVC 网络应用程序中的 Office365 应用程序下载电子邮件。我正在为在 Azure Active Directory 上配置应用程序权限而苦苦挣扎。许可说:"Read mail in All mailboxes" 但是我想选择它可以 access/read 的邮箱。

有谁知道如何在 AAD 中更具体地设置权限?感谢您的帮助。

string authority = "https://login.microsoftonline.com/" + SettingsHelper.TenantId + "/oauth2/token";

var credential = new ClientCredential(SettingsHelper.ClientId, SettingsHelper.ClientSecret);
AuthenticationContext authContext = new AuthenticationContext(authority);
var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com", credential);
var graphserviceClient = new GraphServiceClient(
    new DelegateAuthenticationProvider(
           (requestMessage) =>
           {
               requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", authResult.AccessToken);

               return Task.FromResult(0);
           }));

//This is Ok. I want to read this.
var allowedEmails = await graphserviceClient.Users["xxx@mydom.com"].Messages.Request().GetAsync();

//This is forbidden. I want to restrict this on AAD level.
var dissabledEmails = await graphserviceClient.Users["yyy@mydom.com"].Messages.Request().GetAsync();

使用客户端凭证流程进行身份验证的应用程序不支持限制应用程序阅读特定电子邮件。

但是你介意分享你正在工作的场景吗? Client Credential 流程用于自信的应用程序,这意味着该应用程序在安全的环境中运行。没有恶意用户可以获得令牌来访问您不想发布的信息。所以你可以限制你自己的应用程序中的资源。希望对你有帮助。