我想从我的Node后端使用Graph API。首先,我通过调用adal-node方法从acquireTokenWithClientCredentials
获取访问令牌。所以我的令牌响应将是
我安装了@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
时我当前的访问令牌是>
我想从我的Node后端使用Graph API。首先,我通过调用AcquireTokenWithClientCredentials方法从adal节点获取访问令牌。因此,我的令牌响应将是我安装...
您不能使用Client credential flow获取/me
端点的访问令牌。您应该改用auth code flow(acquireTokenWithAuthorizationCode
)。然后,您可以呼叫登录用户的/me
。