通过Azure Active Directory访问Graph API的令牌以属性错误结束



我正在尝试调用Graph API:https://graph.microsoft.com/v1.0/me/sendMail.我使用图形资源管理器成功地运行了查询,并在其中向用户授予了Mail.Send权限。如果我在Postman中使用图形资源管理器中的访问令牌,它也可以工作。

但是,如果我使用我自己的访问令牌,我通过调用Azure Active Directory应用程序创建的访问令牌将以以下错误告终:

{
"error": {
"code": "RequestBodyRead",
"message": "The property 'subject' does not exist on type 'Microsoft.OutlookServices.Message'. Make sure to only use property names that are defined by the type or mark the type as open type. REST APIs for this mailbox are currently in preview. You can find more information about the preview REST APIs at https://dev.outlook.com/.",
"innerError": {
"date": "2021-12-23T12:47:23",
"request-id": "cbb00b85-295b-45e2-abc7-f064ec52f994",
"client-request-id": "cbb00b85-295b-45e2-abc7-f064ec52f994"
}
}

消息中的正文是相同的,我只是将访问令牌从图形资源管理器更改为我创建的访问令牌。访问令牌是通过POST请求创建的,目的是:

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
client_id=535fb09-9f3-476-9bf-4f126479986
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret=qWgdYAmab0YSkuL1qPX
&grant_type=client_credentials

我用检查了两个令牌https://jwt.io/如果它们以某种方式变化。唯一奇怪的是参数";aud";观众。我的Token中的值与Graph Explorer中的值不同,但我不知道是否可以更改。

Azure Active Directory应用程序确实具有必要的权限,并且获得管理员同意。在此处输入图像描述

非常感谢您的帮助。

您已授予应用程序委派权限,允许您的应用程序代表用户调用API。但是,在不涉及用户的情况下,只使用应用程序凭据进行身份验证。在这种情况下,仅应用"应用程序"权限。

您要么需要授予";以任何用户的身份发送邮件";应用程序权限(并使用/users/user-id而不是/me(,或者您需要更改身份验证方式,以便在过程的某个时刻涉及用户。

最新更新