Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added customHosts support #2592

Merged
merged 3 commits into from
Jul 7, 2023
Merged
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
1 change: 1 addition & 0 deletions packages/mgt-element/src/Graph.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading