Skip to content

Commit 8c09988

Browse files
committed
Uses proxy settings for authentication.
1 parent 8258166 commit 8c09988

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

src/client/core/aad/auth-provider.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default class AuthProvider {
7474
*
7575
* Until this is resolved, we use one client application per tenant.
7676
*/
77-
const client = this._getClient(tenantId);
77+
const client = await this._getClient(tenantId);
7878

7979
const authRequest = this._authRequest(resourceURI, tenantId);
8080
try {
@@ -157,24 +157,39 @@ export default class AuthProvider {
157157
}
158158
}
159159

160-
protected _getClient(tenantId: string): PublicClientApplication {
160+
protected async _getClient(tenantId: string):
161+
Promise<PublicClientApplication> {
161162
if (tenantId in this._clients) {
162163
return this._clients[tenantId];
163164
}
164-
const client = this._createClient(tenantId);
165+
const client = await this._createClient(tenantId);
165166
if (!this._primaryClient) {
166167
this._primaryClient = client;
167168
}
168169
this._clients[tenantId] = client;
169170
return client;
170171
}
171172

172-
private _createClient(tenantId: string): PublicClientApplication {
173-
return new PublicClientApplication({
173+
private async _createClient(tenantId: string):
174+
Promise<PublicClientApplication> {
175+
const proxySettings = await this.app.proxySettings.settings;
176+
const proxyUrl = proxySettings?.http.toString();
177+
if (proxyUrl) {
178+
log.info(`[${tenantId}] Proxying auth endpoints through ` +
179+
proxyUrl);
180+
}
181+
182+
const authority =
183+
`${this.app.properties.azureEnvironment.aadUrl}${tenantId}/`;
184+
185+
return new PublicClientApplication({
186+
system: {
187+
proxyUrl
188+
},
174189
auth: {
175190
clientId: this.config.clientId,
176-
authority:
177-
`${this.app.properties.azureEnvironment.aadUrl}${tenantId}/`
191+
authority,
192+
knownAuthorities: [authority]
178193
},
179194
cache: {
180195
cachePlugin: this._cachePlugin

src/client/proxy/proxy-settings.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ProxyCredentials, ProxySetting, ProxySettings,
99
} from "get-proxy-settings";
1010
import { BehaviorSubject } from "rxjs";
11-
import { filter, map, take } from "rxjs/operators";
11+
import { map, take } from "rxjs/operators";
1212

1313
export interface ProxySettingConfiguration {
1414
settings: ProxySettings | null;
@@ -30,7 +30,6 @@ export class ProxySettingsManager {
3030

3131
public get settings(): Promise<ProxySettings | null> {
3232
return this._settings.pipe(
33-
filter(x => x !== null),
3433
take(1),
3534
map(x => x?.settings),
3635
).toPromise();

0 commit comments

Comments
 (0)