microsoft-graph-api - 'ImplicitMSALAuthenticationProvider' 不是从 '@microsoft/microsoft-graph-client' 导出的

标签 microsoft-graph-api

我正在尝试将 Outlook API 与我的 React 应用程序集成。当我尝试使用 microsoft-graph-client 实现身份验证时,遇到以下错误。

'ImplicitMSALAuthenticationProvider' is not exported from '@microsoft/microsoft-graph-client' (imported as 'MicrosoftGraph')

我怎样才能消除这个错误?

import * as Msal from "msal";
import * as MicrosoftGraph from "@microsoft/microsoft-graph-client";

export const Authenticate = () => {
    const msalConfig = {
        appId: 'ea54b9e3-a1ba-44a2-b6f3-5d766f8c32e3',
        scopes: [
          "user.read",
          "calendars.read"
        ]
      }
      const graphScopes = ["user.read", "mail.send"];
      const msalApplication = new Msal.UserAgentApplication(msalConfig);
const options = new MicrosoftGraph.MSALAuthenticationProviderOptions(graphScopes);
const authProvider = new MicrosoftGraph.ImplicitMSALAuthenticationProvider(msalApplication, options);
const AuthOptions = {
    authProvider, // An instance created from previous step
};
const Client = MicrosoftGraph.Client;
return Client.initWithMiddleware(AuthOptions);
}

最佳答案

遗憾的是,ImplicitMSALAuthenticationProvider 未显式导出。要解决此问题,您需要显式导入类:

import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider";

然后这允许您实例化提供者,

const authProvider = new ImplicitMSALAuthenticationProvider(this.userAgentApplication, { scopes });

关于microsoft-graph-api - 'ImplicitMSALAuthenticationProvider' 不是从 '@microsoft/microsoft-graph-client' 导出的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58049379/

相关文章:

office365 - Office 365 Graph - 从最近的文件查询中删除了 "name"属性

azure - 无法使用 Microsoft Graph API 登录服务主体

powershell - 使用 MS Graph(或 PowerShell)创建 MS Teams 聊天

azure - PowerShell MgGraph 命令引发 TypeNotFound 错误

Azure Active Directory - 获取租户列表

azure - 使用 Microsoft Graph API 更新 Azure AD 应用程序 key 或 secret - BadRequest 错误

c# - Webhook 订阅验证消息中没有 ClientState

asp.net-core - Blazor Webassembly 身份验证事件

c# - 如何使用 Microsoft.Graph 将文件附加到 Sharepoint 中的项目

office365 - 如何使用Microsoft Graph API获取Office365邮件的MIME内容?