Mas*_*nka 5 authorization office365-apps azure-active-directory azure-ad-graph-api
我正在尝试通过 MVC Web 应用程序中的 Office365 应用程序下载电子邮件。我正在努力在 Azure Active Directory 上配置应用程序权限。权限说:“阅读所有邮箱中的邮件”,但是我想选择它可以访问/读取哪些邮箱。
有谁知道如何更具体地在 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();
Run Code Online (Sandbox Code Playgroud)
使用客户端凭据流程进行身份验证的应用程序不支持限制应用程序读取特定电子邮件。
但您介意分享一下您正在工作的场景吗?客户端凭据流用于可信应用程序,这意味着该应用程序在安全的环境中运行。没有恶意用户可以获得令牌来访问您不想发布的信息。所以你可以限制你自己的应用程序中的资源。希望它有帮助。
| 归档时间: |
|
| 查看次数: |
1168 次 |
| 最近记录: |