Skip to content

Commit

Permalink
feat: move electron to peer dependency (#3046)
Browse files Browse the repository at this point in the history
move electron to a peer dependency, this is not a breaking change as projects implementing electron applications specify the version of electron that they use as a devDependency by convention. The version range allowed is very wide and covers the old version that we were using up to the current version of electron.

fix: make scope aware requests work for electron apps
  adds support for passing approved scopes to front end via context bridge
  • Loading branch information
gavinbarron committed Feb 23, 2024
1 parent f1ffe5e commit c572c01
Show file tree
Hide file tree
Showing 44 changed files with 153 additions and 188 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/got-npm-9.6.0-80edc15fd0-941807bd97.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/keyv-npm-3.1.0-81c9ff4454-bb7e8f3acf.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -156,8 +156,5 @@
"pre-commit": "npm run prettier:check && npm run lint"
}
},
"resolutions": {
"responselike": "2.0.0"
},
"packageManager": "yarn@3.6.3"
}
14 changes: 8 additions & 6 deletions packages/providers/mgt-electron-provider/package.json
Expand Up @@ -44,13 +44,15 @@
"dependencies": {
"@azure/msal-node": "^1.0.3",
"@microsoft/mgt-element": "*",
"@microsoft/microsoft-graph-client": "3.0.2",
"electron": "^11.0.2"
"@microsoft/microsoft-graph-client": "3.0.2"
},
"peerDependencies": {
"electron": ">=11.0.2 <29.0.0"
},
"devDependencies": {
"electron": "^28.2.2"
},
"publishConfig": {
"directory": "dist"
},
"resolutions": {
"responselike": "2.0.0"
}
}
}
Expand Up @@ -18,7 +18,7 @@ import {
SilentFlowRequest
} from '@azure/msal-node';
import { AuthenticationProviderOptions } from '@microsoft/microsoft-graph-client';
import { GraphEndpoint } from '@microsoft/mgt-element';
import { arraysAreEqual, GraphEndpoint } from '@microsoft/mgt-element';
import { BrowserWindow, ipcMain } from 'electron';
import { CustomFileProtocolListener } from './CustomFileProtocol';
import { REDIRECT_URI, COMMON_AUTHORITY_URL } from './Constants';
Expand Down Expand Up @@ -197,6 +197,15 @@ export class ElectronAuthenticator {
private static authInstance: ElectronAuthenticator;

private _approvedScopes: string[];
protected get approvedScopes(): string[] {
return this._approvedScopes;
}
protected set approvedScopes(value: string[]) {
if (!arraysAreEqual(value, this._approvedScopes)) {
this._approvedScopes = value;
this.mainWindow.webContents.send('approvedScopes', value);
}
}

/**
* Creates an instance of ElectronAuthenticator.
Expand Down Expand Up @@ -346,7 +355,7 @@ export class ElectronAuthenticator {
authResponse = await this.getTokenSilent(request, scopes);
}
if (authResponse) {
this._approvedScopes = authResponse.scopes;
this.approvedScopes = authResponse.scopes;
return authResponse.accessToken;
}
return undefined;
Expand Down Expand Up @@ -410,7 +419,7 @@ export class ElectronAuthenticator {
*/
private async setAccountFromResponse(response: AuthenticationResult) {
if (response) {
this._approvedScopes = response.scopes;
this.approvedScopes = response.scopes;
this.account = response?.account || undefined;
} else {
this.account = await this.getAccount();
Expand Down
Expand Up @@ -25,6 +25,7 @@ export interface IContextBridgeImpl {
token: (options?: AuthenticationProviderOptions) => Promise<string>;
login: () => Promise<void>;
logout: () => Promise<void>;
approvedScopes: (callback: (event: IpcRendererEvent, approvedScopes: string[]) => void) => void;
}

/**
Expand Down Expand Up @@ -72,6 +73,9 @@ export class ElectronContextBridgeProvider extends IProvider {
Providers.globalProvider.setState(ProviderState.SignedOut);
}
});
this.contextBridge.approvedScopes((_event, approvedScopes) => {
Providers.globalProvider.approvedScopes = approvedScopes;
});
}

/**
Expand Down

0 comments on commit c572c01

Please sign in to comment.