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

时间:2019-09-22 12:49:15

标签: microsoft-graph

我正在尝试将Outlook API与我的React App集成在一起。当我尝试使用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);
}

1 个答案:

答案 0 :(得分:1)

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

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

然后,您可以实例化提供程序,

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