Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class DevTranslationsLoader {
this.translations.clear();
if (!this.translationFiles) {
this.translationFiles = await glob("**/*.i18n.yml", {
ignore: "node_modules/**/*",
ignore: ["node_modules/**/*", "release/**/*"],
});
}
await this._processFiles(this.translationFiles, duplicateCallback);
Expand Down
8 changes: 7 additions & 1 deletion desktop/src/client/core/aad/auth-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import { AuthObserver } from "./auth-observer";
import { shell } from "electron";
import { AuthLoopbackClient } from "./auth-loopback-client";
import { ProxyNetworkClient } from "./proxy-network-client";

import "global-agent/bootstrap";

const MSAL_SCOPES = ["user_impersonation"];

Expand Down Expand Up @@ -245,18 +248,21 @@
private async _createClient(tenantId: string):
Promise<PublicClientApplication> {
const proxyUrl = await this._loadProxyUrl();
let networkClient;

if (proxyUrl) {
log.info(`[${tenantId}] Proxying auth endpoints through ` +
proxyUrl);
process.env.GLOBAL_AGENT_HTTP_PROXY = proxyUrl;
networkClient = new ProxyNetworkClient(proxyUrl);

Check warning on line 257 in desktop/src/client/core/aad/auth-provider.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/auth-provider.ts#L256-L257

Added lines #L256 - L257 were not covered by tests
}

const authority =
`${this.app.properties.azureEnvironment.aadUrl}${tenantId}/`;

return new PublicClientApplication({
system: {
proxyUrl
networkClient
},
auth: {
clientId: this.config.clientId,
Expand Down
55 changes: 55 additions & 0 deletions desktop/src/client/core/aad/proxy-network-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import type { INetworkModule, NetworkRequestOptions, NetworkResponse } from "@azure/msal-node";
import * as HttpsProxyAgent from "https-proxy-agent";
import fetch from "node-fetch";

/**
* Placeholder for msal-node's network module which uses node-fetch to support
* HTTP proxy configurations with authorization
*
* @see https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/6527#issuecomment-2077953882
*/
export class ProxyNetworkClient implements INetworkModule {
private proxyAgent: HttpsProxyAgent;
constructor(proxyUrl: string) {
this.proxyAgent = new HttpsProxyAgent(proxyUrl);

Check warning on line 14 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L14

Added line #L14 was not covered by tests
}

sendGetRequestAsync<T>(url: string, options?: NetworkRequestOptions): Promise<NetworkResponse<T>> {
return this.sendRequestAsync(url, "GET", options);

Check warning on line 18 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L18

Added line #L18 was not covered by tests
}
sendPostRequestAsync<T>(url: string, options?: NetworkRequestOptions): Promise<NetworkResponse<T>> {
return this.sendRequestAsync(url, "POST", options);

Check warning on line 21 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L21

Added line #L21 was not covered by tests
}

private async sendRequestAsync<T>(
url: string,
method: "GET" | "POST",
options: NetworkRequestOptions = {},
): Promise<NetworkResponse<T>> {
try {
const requestOptions = {

Check warning on line 30 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L29-L30

Added lines #L29 - L30 were not covered by tests
method: method,
headers: options.headers,
body: method === "POST" ? options.body : undefined,
agent: this.proxyAgent,
};

const response = await fetch(url, requestOptions);
const data = await response.json() as any;

Check warning on line 38 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L37-L38

Added lines #L37 - L38 were not covered by tests

const headersObj: Record<string, string> = {};
response.headers.forEach((value, key) => {
headersObj[key] = value;

Check warning on line 42 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L40-L42

Added lines #L40 - L42 were not covered by tests
});

return {

Check warning on line 45 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L45

Added line #L45 was not covered by tests
headers: headersObj,
body: data,
status: response.status,
};
} catch (err) {
console.error("Proxy request error", err);
throw err;

Check warning on line 52 in desktop/src/client/core/aad/proxy-network-client.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/aad/proxy-network-client.ts#L51-L52

Added lines #L51 - L52 were not covered by tests
}
}
}
41 changes: 41 additions & 0 deletions desktop/src/client/core/batch-explorer-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
this._setupProcessEvents();
this._registerFileProtocol();
await this.proxySettings.init();
this._applyProxySettings();

Check warning on line 89 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L89

Added line #L89 was not covered by tests
this.storageBlobAdapter.init();
}

Expand Down Expand Up @@ -365,4 +366,44 @@
callback({ cancel: false, requestHeaders: details.requestHeaders });
});
}

private async _trustedDomains(): Promise<string[]> {
return [

Check warning on line 371 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L371

Added line #L371 was not covered by tests
"https://raw.githubusercontent.com",
"https://batch.azure.com", // Public data-plane API calls
this.properties.azureEnvironment.aadUrl,
this.properties.azureEnvironment.arm,
this.properties.azureEnvironment.batch,
this.properties.azureEnvironment.msGraph,
this.properties.azureEnvironment.storageEndpoint
].map(url => {
try {

Check warning on line 380 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L380

Added line #L380 was not covered by tests
// Ensure the URL has a protocol (default to "https://")
const normalized = url.startsWith("http") ? url : `https://${url}`;
return new URL(normalized).hostname;

Check warning on line 383 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L383

Added line #L383 was not covered by tests
} catch (error) {
console.error(`Invalid URL: ${url}`, error);
return null; // Handle invalid URLs gracefully

Check warning on line 386 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L385-L386

Added lines #L385 - L386 were not covered by tests
}
}).filter(Boolean);
}

private async _applyProxySettings() {
const settings = await this.proxySettings.settings;

Check warning on line 392 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L392

Added line #L392 was not covered by tests

const conf = settings.http || settings.https;
const proxyUrl = `${conf.protocol}://${conf.host}:${conf.port}`;

Check warning on line 395 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L395

Added line #L395 was not covered by tests

session.defaultSession.setProxy({ proxyRules: proxyUrl });

Check warning on line 397 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L397

Added line #L397 was not covered by tests

const trustedDomains = await this._trustedDomains();
session.defaultSession.setCertificateVerifyProc((request, verifyCert) => {

Check warning on line 400 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L399-L400

Added lines #L399 - L400 were not covered by tests
if (trustedDomains.some(host => request.hostname.includes(host))) {
verifyCert(0); // trust the certificate

Check warning on line 402 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L402

Added line #L402 was not covered by tests
} else {
console.error("Untrusted certificate", request.hostname);
verifyCert(-3);

Check warning on line 405 in desktop/src/client/core/batch-explorer-application.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/batch-explorer-application.ts#L404-L405

Added lines #L404 - L405 were not covered by tests
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

private async _loadDevelopementTranslations() {
this.translations = await this.devTranslationsService.load((key, source) => {
log.error(`Translation with key ${key} already exists. ${source} is redefining it`);
log.warn(`Translation with key ${key} already exists. ${source} is redefining it`);

Check warning on line 38 in desktop/src/client/core/i18n/client-translations-loader.service.ts

View check run for this annotation

Codecov / codecov/patch

desktop/src/client/core/i18n/client-translations-loader.service.ts#L38

Added line #L38 was not covered by tests
});
await this._loadLocaleTranslations();
}
Expand Down