microsoft-graph-api - 'ImplicitMSALAuthenticationProvider' 不是从'@microsoft/microsoft-graph-client' 导出的
问题描述
我正在尝试将 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);
}
解决方案
不幸的是,ImplicitMSALAuthenticationProvider 没有显式导出。要解决此问题,您需要显式导入该类:
import { ImplicitMSALAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/ImplicitMSALAuthenticationProvider";
然后,这允许您实例化提供程序,
const authProvider = new ImplicitMSALAuthenticationProvider(this.userAgentApplication, { scopes });
推荐阅读
- reactjs - 警告:无法对未安装的组件执行 React 状态更新
- javascript - Date.toLocaleString() 返回无效的语言标签:en_GB 但 Java.util.Locale 类返回英国的 en_GB 语言环境
- android - 使用 mimekit 在 xamarin 中为 android 和 iOS 读取 p7m 文件
- c++ - std::vector 默认未初始化 ctor
- python - 从工厂日志数据制作图表
- c# - Lambda 表达式组
- html - 使边框变粗并改变颜色或在 awesome-bootstrap-checkbox 上产生阴影效果?
- node.js - ExpressJS & Passport pass req, res
- c# - 带有 FCM 的 Xamarin Android 应用程序在杀死并再次重新打开后崩溃
- netbeans - Netbeans 自动完成 XSL-FO