Restrict Office365 App “Read mail in All mailboxes

2019-07-21 21:26发布

I'm trying to download emails through Office365 app in MVC web app. And I'm struggling with configuring app permissions on Azure Active directory. Permission says: "Read mail in All mailboxes" however I want to choose which mailboxes it can access/read.

Does anyone know ho to be more specific in setting up permissions in AAD? Thanks for any help.

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();

enter image description here

enter image description here

1条回答
再贱就再见
2楼-- · 2019-07-21 22:08

The app which used the Client Credential flow to authenticate doesn't support the restrict the app to read the specific emails.

But would you mind share the scenario you are working? The Client Credential flow is used for the confident app which means the app is working in a safe environment. There is no malicious user could get the token to access the information you don't want to publish. So you can just limit the resource in your own app. Hope it is helpful.

查看更多
登录 后发表回答