Skip to content

[msal-common][msal-browser] Fix issue where config was being overwritten by undefined values #1631

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

Merged
merged 6 commits into from
May 11, 2020
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
13 changes: 7 additions & 6 deletions lib/msal-browser/src/config/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
import { AuthOptions, SystemOptions, LoggerOptions, INetworkModule, LogLevel } from "@azure/msal-common";
import { AuthOptions, SystemOptions, LoggerOptions, INetworkModule, LogLevel, DEFAULT_SYSTEM_OPTIONS } from "@azure/msal-common";
import { BrowserUtils } from "../utils/BrowserUtils";
import { BrowserConstants } from "../utils/BrowserConstants";

Expand Down Expand Up @@ -96,7 +96,8 @@ const DEFAULT_LOGGER_OPTIONS: LoggerOptions = {
};

// Default system options for browser
const DEFAULT_SYSTEM_OPTIONS: BrowserSystemOptions = {
const DEFAULT_BROWSER_SYSTEM_OPTIONS: BrowserSystemOptions = {
...DEFAULT_SYSTEM_OPTIONS,
loggerOptions: DEFAULT_LOGGER_OPTIONS,
networkClient: BrowserUtils.getBrowserNetworkClient(),
windowHashTimeout: DEFAULT_POPUP_TIMEOUT_MS,
Expand All @@ -114,11 +115,11 @@ const DEFAULT_SYSTEM_OPTIONS: BrowserSystemOptions = {
*
* @returns TConfiguration object
*/
export function buildConfiguration({ auth, cache = {}, system = {}}: Configuration): Configuration {
export function buildConfiguration({ auth: userInputAuth, cache: userInputCache, system: userInputSystem }: Configuration): Configuration {
const overlayedConfig: Configuration = {
auth: { ...DEFAULT_AUTH_OPTIONS, ...auth },
cache: { ...DEFAULT_CACHE_OPTIONS, ...cache },
system: { ...DEFAULT_SYSTEM_OPTIONS, ...system }
auth: { ...DEFAULT_AUTH_OPTIONS, ...userInputAuth },
cache: { ...DEFAULT_CACHE_OPTIONS, ...userInputCache },
system: { ...DEFAULT_BROWSER_SYSTEM_OPTIONS, ...userInputSystem }
};
return overlayedConfig;
}
4 changes: 2 additions & 2 deletions lib/msal-browser/test/config/Configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ describe("Configuration.ts Class Unit Tests", () => {
expect(emptyConfig.system.networkClient).to.be.not.null.and.not.undefined;
expect(emptyConfig.system.windowHashTimeout).to.be.not.null.and.not.undefined;
expect(emptyConfig.system.windowHashTimeout).to.be.eq(DEFAULT_POPUP_TIMEOUT_MS);
expect(emptyConfig.system.tokenRenewalOffsetSeconds).to.be.undefined;
expect(emptyConfig.system.telemetry).to.be.undefined;
expect(emptyConfig.system.tokenRenewalOffsetSeconds).to.be.eq(300);
expect(emptyConfig.system.telemetry).to.be.null;
});

it("Tests default logger", () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/src/config/ClientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const DEFAULT_AUTH_OPTIONS: AuthOptions = {
postLogoutRedirectUri: ""
};

const DEFAULT_SYSTEM_OPTIONS: SystemOptions = {
export const DEFAULT_SYSTEM_OPTIONS: SystemOptions = {
tokenRenewalOffsetSeconds: DEFAULT_TOKEN_RENEWAL_OFFSET_SEC,
telemetry: null
};
Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { SPAClient } from "./client/SPAClient";
export { AuthorizationCodeClient } from "./client/AuthorizationCodeClient";
export { DeviceCodeClient } from "./client/DeviceCodeClient";
export { RefreshTokenClient } from "./client/RefreshTokenClient";
export { AuthOptions, SystemOptions, LoggerOptions, TelemetryOptions } from "./config/ClientConfiguration";
export { AuthOptions, SystemOptions, LoggerOptions, TelemetryOptions, DEFAULT_SYSTEM_OPTIONS } from "./config/ClientConfiguration";
export { ClientConfiguration } from "./config/ClientConfiguration";
// Account
export { Account } from "./account/Account";
Expand Down
1 change: 0 additions & 1 deletion lib/msal-common/src/request/ScopeSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export class ScopeSet {
const sizeOtherScopes = otherScopes.containsScope(Constants.OFFLINE_ACCESS_SCOPE)? otherScopes.getScopeCount() - 1 : otherScopes.getScopeCount();
const sizeThisScopes = this.containsScope(Constants.OFFLINE_ACCESS_SCOPE)? this.getScopeCount() - 1: this.getScopeCount();
const sizeUnionScopes = unionScopes.has(Constants.OFFLINE_ACCESS_SCOPE)? unionScopes.size - 1: unionScopes.size;

return sizeUnionScopes < (sizeThisScopes + sizeOtherScopes);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/msal-common/test/config/Configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { version } from "../../package.json";
import {TEST_CONFIG} from "../utils/StringConstants";


describe("Configuration.ts Class Unit Tests", () => {
describe("ClientConfiguration.ts Class Unit Tests", () => {

it("buildConfiguration assigns default functions", async () => {
const emptyConfig: ClientConfiguration = buildClientConfiguration({});
Expand Down