Skip to content

Commit 1f97215

Browse files
authored
fix: adds customHosts support for non-graph domain requests (#2592)
added custom hosts passthrough added converter to custom-hosts attribute
1 parent e704cce commit 1f97215

File tree

7 files changed

+116
-37536
lines changed

7 files changed

+116
-37536
lines changed

packages/mgt-element/src/Graph.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export const createFromProvider = (provider: IProvider, version?: string, compon
159159
const baseURL = provider.baseURL ? provider.baseURL : MICROSOFT_GRAPH_DEFAULT_ENDPOINT;
160160
const client = Client.initWithMiddleware({
161161
middleware: chainMiddleware(...middleware),
162+
customHosts: typeof provider.customHosts === undefined ? null : new Set(provider.customHosts),
162163
baseUrl: baseURL
163164
});
164165

packages/mgt-element/src/components/baseProvider.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ export abstract class MgtBaseProvider extends MgtBaseComponent {
7878
})
7979
public baseUrl: GraphEndpoint;
8080

81+
/**
82+
* Custom Hosts to be passed through to the graph client
83+
*
84+
* @memberof MgtBaseProvider
85+
*/
86+
@property({
87+
attribute: 'custom-hosts',
88+
type: String,
89+
converter: newValue => newValue.split(',').map(s => s.trim())
90+
})
91+
public customHosts?: string[];
92+
8193
private _provider: IProvider;
8294

8395
/**

packages/mgt-element/src/providers/IProvider.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,19 @@ export abstract class IProvider implements AuthenticationProvider {
6767
return this._baseURL;
6868
}
6969

70+
private _customHosts?: string[] = undefined;
71+
72+
/**
73+
* Custom Hostnames to allow graph client to utilize
74+
*/
75+
public set customHosts(hosts: string[] | undefined) {
76+
this._customHosts = hosts;
77+
}
78+
79+
public get customHosts(): string[] | undefined {
80+
return this._customHosts;
81+
}
82+
7083
/**
7184
* Enable/Disable incremental consent
7285
*

packages/providers/mgt-msal2-provider/src/Msal2Provider.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ export interface Msal2Config extends Msal2ConfigBase {
146146
* The base URL for the graph client
147147
*/
148148
baseURL?: GraphEndpoint;
149+
150+
/**
151+
* CustomHosts
152+
*
153+
* @type {string[]}
154+
* @memberof Msal2Config
155+
*/
156+
customHosts?: string[];
149157
}
150158

151159
/**
@@ -394,6 +402,7 @@ export class Msal2Provider extends IProvider {
394402
this.isMultipleAccountEnabled =
395403
typeof msal2config.isMultiAccountEnabled !== 'undefined' ? msal2config.isMultiAccountEnabled : true;
396404
this.baseURL = typeof msal2config.baseURL !== 'undefined' ? msal2config.baseURL : this.baseURL;
405+
this.customHosts = msal2config.customHosts;
397406

398407
this.graph = createFromProvider(this);
399408
try {

packages/providers/mgt-msal2-provider/src/mgt-msal2-provider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ export class MgtMsal2Provider extends MgtBaseProvider {
195195
config.baseURL = this.baseUrl;
196196
}
197197

198+
if (this.customHosts) {
199+
config.customHosts = this.customHosts;
200+
}
201+
198202
this.provider = new Msal2Provider(config);
199203
Providers.globalProvider = this.provider;
200204
}

tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// "incremental": true, /* Enable incremental compilation */
77
"target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
88
"module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
9-
"lib": ["dom", "es5", "DOM.Iterable"] /* Specify library files to be included in the compilation. */,
9+
"lib": ["dom", "es5", "es6", "DOM.Iterable"] /* Specify library files to be included in the compilation. */,
1010
// "allowJs": true, /* Allow javascript files to be compiled. */
1111
// "checkJs": true, /* Report errors in .js files. */
1212
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */

0 commit comments

Comments
 (0)