Chandan Singh
Chandan Singh

Reputation: 7

Electron App with Azure AD - without Interactive browser

I am trying to integrate Azure AD authentication with my Electron App (with Angular). I took reference from this link and able to integrate: https://learn.microsoft.com/en-us/azure/active-directory/develop/tutorial-v2-nodejs-desktop

Issue: It's using getTokenInteractive() method and it's navigating to an external browser. As per my requirement we don't have to navigate to an external browser, it should open the UI inside my electron App where end users can provide their credentials. Another option if possible we can open the Azure AD url part of my electron App.

I took reference from this link and able to integrate: 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;
        }
    }

Upvotes: 0

Views: 888

Answers (1)

Miiih
Miiih

Reputation: 1

I imported BrowserWindows from electron and used the getAllWindows method to return all open windows, this method returns an array.

Hope this helps.

const { BrowserWindow } = require("electron");
const openBrowser = async (url) => {
    const win = BrowserWindow.getAllWindows();
    win[0].loadURL(url);
  };

Upvotes: 0

Related Questions