Skip to content

Commit

Permalink
fix: adds customHosts support for non-graph domain requests (#2592)
Browse files Browse the repository at this point in the history
added custom hosts passthrough
added converter to custom-hosts attribute
  • Loading branch information
techienickb committed Jul 7, 2023
1 parent e704cce commit 1f97215
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 37,536 deletions.
1 change: 1 addition & 0 deletions packages/mgt-element/src/Graph.ts
Expand Up @@ -159,6 +159,7 @@ export const createFromProvider = (provider: IProvider, version?: string, compon
const baseURL = provider.baseURL ? provider.baseURL : MICROSOFT_GRAPH_DEFAULT_ENDPOINT;
const client = Client.initWithMiddleware({
middleware: chainMiddleware(...middleware),
customHosts: typeof provider.customHosts === undefined ? null : new Set(provider.customHosts),
baseUrl: baseURL
});

Expand Down
12 changes: 12 additions & 0 deletions packages/mgt-element/src/components/baseProvider.ts
Expand Up @@ -78,6 +78,18 @@ export abstract class MgtBaseProvider extends MgtBaseComponent {
})
public baseUrl: GraphEndpoint;

/**
* Custom Hosts to be passed through to the graph client
*
* @memberof MgtBaseProvider
*/
@property({
attribute: 'custom-hosts',
type: String,
converter: newValue => newValue.split(',').map(s => s.trim())
})
public customHosts?: string[];

private _provider: IProvider;

/**
Expand Down
13 changes: 13 additions & 0 deletions packages/mgt-element/src/providers/IProvider.ts
Expand Up @@ -67,6 +67,19 @@ export abstract class IProvider implements AuthenticationProvider {
return this._baseURL;
}

private _customHosts?: string[] = undefined;

/**
* Custom Hostnames to allow graph client to utilize
*/
public set customHosts(hosts: string[] | undefined) {
this._customHosts = hosts;
}

public get customHosts(): string[] | undefined {
return this._customHosts;
}

/**
* Enable/Disable incremental consent
*
Expand Down
9 changes: 9 additions & 0 deletions packages/providers/mgt-msal2-provider/src/Msal2Provider.ts
Expand Up @@ -146,6 +146,14 @@ export interface Msal2Config extends Msal2ConfigBase {
* The base URL for the graph client
*/
baseURL?: GraphEndpoint;

/**
* CustomHosts
*
* @type {string[]}
* @memberof Msal2Config
*/
customHosts?: string[];
}

/**
Expand Down Expand Up @@ -394,6 +402,7 @@ export class Msal2Provider extends IProvider {
this.isMultipleAccountEnabled =
typeof msal2config.isMultiAccountEnabled !== 'undefined' ? msal2config.isMultiAccountEnabled : true;
this.baseURL = typeof msal2config.baseURL !== 'undefined' ? msal2config.baseURL : this.baseURL;
this.customHosts = msal2config.customHosts;

this.graph = createFromProvider(this);
try {
Expand Down
Expand Up @@ -195,6 +195,10 @@ export class MgtMsal2Provider extends MgtBaseProvider {
config.baseURL = this.baseUrl;
}

if (this.customHosts) {
config.customHosts = this.customHosts;
}

this.provider = new Msal2Provider(config);
Providers.globalProvider = this.provider;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.base.json
Expand Up @@ -6,7 +6,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "es2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": ["dom", "es5", "DOM.Iterable"] /* Specify library files to be included in the compilation. */,
"lib": ["dom", "es5", "es6", "DOM.Iterable"] /* Specify library files to be included in the compilation. */,
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
Expand Down

0 comments on commit 1f97215

Please sign in to comment.