我正在尝试将 Azure AD 身份验证与我的 Electron 应用程序(使用 Angular)集成。我从此链接中引用并能够集成:https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-nodejs-desktop
问题:它使用 getTokenInteractive() 方法并且导航到外部浏览器。根据我的要求,我们不必导航到外部浏览器,它应该打开我的电子应用程序内的 UI,最终用户可以在其中提供他们的凭据。 如果可能的话,另一种选择是我们可以打开我的电子应用程序的 Azure AD url 部分。
我从此链接中引用并能够集成:https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-nodejs-desktop
async getTokenInteractive(tokenRequest) {
try {
const openBrowser = async (url) => {
await shell.openExternal(url);
};
const authResponse = await this.clientApplication.acquireTokenInteractive({
...tokenRequest,
openBrowser,
successTemplate: '<h1>Successfully signed in!</h1> <p>You can close this window now.</p>',
errorTemplate: '<h1>Oops! Something went wrong</h1> <p>Check the console for more information.</p>',
});
return authResponse;
} catch (error) {
throw error;
}
}
我从Electron导入了BrowserWindows,并使用getAllWindows方法返回所有打开的窗口,该方法返回一个数组。
希望这有帮助。
const { BrowserWindow } = require("electron");
const openBrowser = async (url) => {
const win = BrowserWindow.getAllWindows();
win[0].loadURL(url);
};