MicrosoftGraph 的列表消息 API return 拒绝访问消息

MicrosoftGraph's list messages API return access denied message

MicrosoftGraph Outlook Mail's List Message API允许我列出管理员用户的消息(授权应用程序生成令牌),但不允许获取其他用户的消息。我尝试了以下 API 调用

https://graph.microsoft.com/v1.0/users/user@microsoft-demo.info/messages

它returns下面的错误信息。

Status Code: 403
{
    "error": {
        "code": "ErrorAccessDenied",
        "message": "Access is denied. Check credentials and try again.",
        "innerError": {
            "request-id": "2c567919-e538-456a-9a90-74fa43685bd1",
            "date": "2016-11-30T10:37:58"
        }
    }
}

请帮我解决问题。

注意:我使用代码流进行身份验证,它是一个多租户应用程序。是否可以为多租户应用程序实施令牌流?

从你的问题来看,不清楚你使用的是哪种身份验证流程,但我怀疑你使用的是身份验证代码流程。

如果您使用身份验证代码流程和用户委派权限,则无论用户是普通用户还是管理员,您都只能访问当前用户的消息。

Sample using auth code flow:

var ctx = new AuthenticationContext(authority + tenant);
var t = await ctx.AcquireTokenAsync(resource, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));

只有通过客户端凭据流和应用程序权限才能检索任何用户的消息。

.Sample using client credentials flow:

var ctx = new AuthenticationContext(authority + tenant, new TokenCache());
var t = ctx.AcquireToken(resource, new ClientCredential(clientId, clientSecret));