我成功地为 Microsoft Graph 设置了 OAuth 2.0 客户端凭据,我获得了授权 token 没有问题,订阅了接收多个用户的电子邮件 webhook,并收到了这些电子邮件通知。
在 Azure 门户中,我将应用程序设置为具有“以任何用户身份发送邮件”的 Microsoft Graph 应用程序级权限。
我正在尝试使用 Graph 转发电子邮件,但收到 BadRequest
错误:
{
"error": {
"code": "BadRequest",
"message":
"Current authenticated context is not valid for this request. This occurs when a request is made to an endpoint that requires user sign-in. For example, /me requires a signed-in user. Acquire a token on behalf of a user to make requests to these endpoints. Use the OAuth 2.0 authorization code flow for mobile and native apps and the OAuth 2.0 implicit flow for single-page web apps.",
"innerError": {
"request-id": "a64c4533-9389-4284-8cf5-68fcadf21832",
"date": "2018-05-27T17:34:29"
}
}
}
这就是我发送请求的方式:
postData(
`${graphVersion}/me/messages/${req.body.emailUid}/forward`,
global.accessToken,
JSON.stringify(forwardConfiguration),
(requestError, data) => {
if (requestError) {
logger.log('error', "Failed to forward email: " + JSON.stringify(requestError));
} else {
logger.log("info", "Successfully forwarded email from " + req.body.email);
}
}
);
最佳答案
您不能将 /me
与客户端凭据一起使用。
这是因为 /me
只是 /user/{currentUser}
的别名。当您使用客户端凭据时,API 也没有“用户”来映射此别名。
您需要明确指定您想要的用户
:
/users/{userId or userPrincipalName}/messages
关于javascript - Microsoft Graph 客户端凭据 - 获取代表用户发送电子邮件的 oauth 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50554876/