microsoft-graph-client在API调用上抛出'# '错误

问题描述 投票:0回答:1

我想从我的Node后端使用Graph API。首先,我通过调用adal-node方法从acquireTokenWithClientCredentials获取访问令牌。所以我的令牌响应将是

token response

我安装了@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时我当前的访问令牌是>

enter image description here

我想从我的Node后端使用Graph API。首先,我通过调用AcquireTokenWithClientCredentials方法从adal节点获取访问令牌。因此,我的令牌响应将是我安装...

azure-active-directory microsoft-graph adal adal.js microsoft-graph-sdks
1个回答
1
投票

您不能使用Client credential flow获取/me端点的访问令牌。您应该改用auth code flowacquireTokenWithAuthorizationCode)。然后,您可以呼叫登录用户的/me

© www.soinside.com 2019 - 2024. All rights reserved.