微软近日发布了 Microsoft Graph Toolkit 的 2.1 版本。
此次新增了一个专为 Electron 应用程序使用的身份验证提供程序,并包含了现有组件和身份验证提供程序的优化和 bug 修复。
Updating your application
更新我们应用程序中引用的 Microsoft Graph Toolkit 到最新版本,我们只需要执行命令
npm i @microsoft/mgt@latest
如果是以 mgt-loader 的方式调用的,那无需做任何操作
新内容
Electron 提供程序
要使用这个新的提供程序,使用如下命令将它添加到应用程序
npm install @microsoft/mgt-element @microsoft/mgt-electron-provider
在加载时使用如下代码创建提供程序对象
import {Providers} from '@microsoft/mgt-element';
import {ElectronProvider} from '@microsoft/mgt-electron-provider/dist/Provider';
Providers.globalProvider = new ElectronProvider();
在主函数中初始化认证器
import { ElectronAuthenticator } from '@microsoft/mgt-electron-provider/dist/Authenticator';
ElectronAuthenticator.initialize({
clientId: '<your_client_id>',
mainWindow: mainWindow
};
);
至此就可以调用 Microsoft Graph 并使用 Microsoft Graph Toolkit 组件了。
其他改进
请查阅 release notes