【发布时间】:2020-11-02 16:14:26
【问题描述】:
我想从我的 Node 后端使用 Graph API。首先,我通过调用acquireTokenWithClientCredentials 方法从adal-node 获取访问令牌。所以我的令牌响应是
我安装了 @microsoft/microsoft-graph-client 软件包并尝试按照此处的指南进行操作 https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/samples/node/main.js 。对于isomorphic-fetch 导入,我安装了isomorphic-fetch 包。
async function bootstrap() {
// ...
const session: TokenResponse = await authenticationService.getSession(); // call the 'acquireTokenWithClientCredentials' function
const client: Client = Client.init({
authProvider: (done) => {
done(null, session.accessToken);
},
});
try {
await client.api('/me').get();
} catch (error) {
throw error;
}
}
API 调用引发异常。但我不知道出了什么问题,因为错误只记录了
(node:20561) UnhandledPromiseRejectionWarning: #<GraphError>
出了什么问题或遗漏了什么?如果您需要更多信息,请告诉我。但我希望我的描述应该足以复制:)提前谢谢。
更新
应用程序未以用户身份登录,应作为后台服务运行。所以也许我无法访问/me,因为应用程序不是用户。但是当我将/me 更新为/users(这个端点应该可以工作)时,我仍然得到同样的错误。
所以我当前访问/users时的访问令牌是
【问题讨论】:
标签: azure-active-directory microsoft-graph-api adal adal.js microsoft-graph-sdks