【问题标题】:'ImplicitMSALAuthenticationProvider' is not exported from '@microsoft/microsoft-graph-client''ImplicitMSALAuthenticationProvider' 不是从'@microsoft/microsoft-graph-client' 导出的
【发布时间】:2020-01-22 18:04:01
【问题描述】:

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

'ImplicitMSALAuthenticationProvider' 不是从 '@microsoft/microsoft-graph-client'(导入为'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);
}

【问题讨论】:

    标签: microsoft-graph-api


    【解决方案1】:

    不幸的是,ImplicitMSALAuthenticationProvider 没有显式导出。要解决此问题,您需要显式导入该类:

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

    这允许您实例化提供程序,

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

    【讨论】:

    • 在我的情况下,这也是必需的: import { MSALAuthenticationProviderOptions } from '@microsoft/microsoft-graph-client/lib/src/MSALAuthenticationProviderOptions'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多