From e8dcdb8e61c00b90e6726ac6ea411c445c449f7a Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Fri, 10 Apr 2020 11:22:35 -0700 Subject: [PATCH 1/8] Move hash processing to constructor for redirect cases --- lib/msal-browser/package.json | 1 - .../src/app/PublicClientApplication.ts | 94 ++++++++----------- .../test/app/PublicClientApplication.spec.ts | 24 +---- 3 files changed, 42 insertions(+), 77 deletions(-) diff --git a/lib/msal-browser/package.json b/lib/msal-browser/package.json index 6c2e2bce54..a1e6b0fd2d 100644 --- a/lib/msal-browser/package.json +++ b/lib/msal-browser/package.json @@ -40,7 +40,6 @@ "doc": "npm run doc:generate && npm run doc:deploy", "doc:generate": "typedoc --mode modules --excludePrivate --excludeProtected --out ./ref ./src/ --gitRevision dev", "doc:deploy": "gh-pages -d ref -a -e ref/msal-browser", - "pretest": "npm link @azure/msal-common", "test": "mocha", "test:coverage": "nyc --reporter=text mocha", "test:coverage:only": "npm run clean:coverage && npm run test:coverage", diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index 1b74598874..920384956c 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -27,9 +27,6 @@ export class PublicClientApplication { // auth functions imported from @azure/msal-common module private authModule: AuthorizationCodeModule; - // callback for error/token response - private authCallback: AuthCallback = null; - // Crypto interface implementation private browserCrypto: CryptoOps; @@ -39,6 +36,9 @@ export class PublicClientApplication { // Network interface implementation private networkClient: INetworkModule; + // Response promise + private tokenExchangePromise: Promise; + /** * @constructor * Constructor for the PublicClientApplication used to instantiate the PublicClientApplication object @@ -88,6 +88,8 @@ export class PublicClientApplication { networkInterface: this.networkClient, storageInterface: this.browserStorage }); + + this.tokenExchangePromise = this.handleRedirectResponse(); } // #region Redirect Flow @@ -109,14 +111,14 @@ export class PublicClientApplication { throw BrowserConfigurationAuthError.createInvalidCallbackObjectError(authCallback); } - // Set the callback object. - this.authCallback = authCallback; - // Check if we need to navigate, otherwise handle hash try { - await this.handleRedirectResponse(); + const tokenResponse = await this.tokenExchangePromise; + if (tokenResponse) { + authCallback(null, tokenResponse); + } } catch (err) { - this.authCallback(err); + authCallback(err); } } @@ -125,7 +127,7 @@ export class PublicClientApplication { * - if true, performs logic to cache and navigate * - if false, handles hash string and parses response */ - private async handleRedirectResponse(): Promise { + private async handleRedirectResponse(): Promise { // Get current location hash from window or cache. const { location: { hash } } = window; const cachedHash = this.browserStorage.getItem(TemporaryCacheKeys.URL_HASH); @@ -141,7 +143,7 @@ export class PublicClientApplication { } else { BrowserUtils.navigateWindow(loginRequestUrl, true); } - return; + return null; } if (!isResponseHash) { @@ -154,6 +156,8 @@ export class PublicClientApplication { BrowserUtils.clearHash(); return this.handleHash(hash); } + + return null; } /** @@ -161,16 +165,16 @@ export class PublicClientApplication { * @param responseHash * @param interactionHandler */ - private async handleHash(responseHash: string): Promise { + private async handleHash(responseHash: string): Promise { const interactionHandler = new RedirectHandler(this.authModule, this.browserStorage); if (!StringUtils.isEmpty(responseHash)) { // Hash contains known properties - handle and return in callback - const tokenResponse = await interactionHandler.handleCodeResponse(responseHash); - this.authCallback(null, tokenResponse); - } else { - // There is no hash - assume we are in clean state and clear any current request data. - this.cleanRequest(); + return interactionHandler.handleCodeResponse(responseHash); } + + // There is no hash - assume we are in clean state and clear any current request data. + this.cleanRequest(); + return null; } /** @@ -179,19 +183,8 @@ export class PublicClientApplication { * @param {@link (AuthenticationParameters:type)} */ loginRedirect(request: AuthenticationParameters): void { - // block the reload if it occurred inside a hidden iframe - BrowserUtils.blockReloadInHiddenIframes(); - - // Check if callback has been set. If not, handleRedirectCallbacks wasn't called correctly. - if (!this.authCallback) { - throw BrowserConfigurationAuthError.createRedirectCallbacksNotSetError(); - } - - // Check if interaction is in progress. Throw error in callback and return if true. - if (this.interactionInProgress()) { - this.authCallback(BrowserAuthError.createInteractionInProgressError()); - return; - } + // Preflight request + this.preflightRequest(); try { // Create redirect interaction handler. @@ -216,19 +209,8 @@ export class PublicClientApplication { * To acquire only idToken, please pass clientId as the only scope in the Authentication Parameters */ acquireTokenRedirect(request: AuthenticationParameters): void { - // block the reload if it occurred inside a hidden iframe - BrowserUtils.blockReloadInHiddenIframes(); - - // Check if callback has been set. If not, handleRedirectCallbacks wasn't called correctly. - if (!this.authCallback) { - throw BrowserConfigurationAuthError.createRedirectCallbacksNotSetError(); - } - - // Check if interaction is in progress. Throw error in callback and return if true. - if (this.interactionInProgress()) { - this.authCallback(BrowserAuthError.createInteractionInProgressError()); - return; - } + // Preflight request + this.preflightRequest(); try { // Create redirect interaction handler. @@ -257,13 +239,8 @@ export class PublicClientApplication { * @returns {Promise.} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object */ async loginPopup(request: AuthenticationParameters): Promise { - // block the reload if it occurred inside a hidden iframe - BrowserUtils.blockReloadInHiddenIframes(); - - // Check if interaction is in progress. Throw error if true. - if (this.interactionInProgress()) { - throw BrowserAuthError.createInteractionInProgressError(); - } + // Preflight request + this.preflightRequest(); // Create login url, which will by default append the client id scope to the call. const navigateUrl = await this.authModule.createLoginUrl(request); @@ -280,13 +257,8 @@ export class PublicClientApplication { * @returns {Promise.} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object */ async acquireTokenPopup(request: AuthenticationParameters): Promise { - // block the reload if it occurred inside a hidden iframe - BrowserUtils.blockReloadInHiddenIframes(); - - // Check if interaction is in progress. Throw error if true. - if (this.interactionInProgress()) { - throw BrowserAuthError.createInteractionInProgressError(); - } + // Preflight request + this.preflightRequest(); // Create acquire token url. const navigateUrl = await this.authModule.createAcquireTokenUrl(request); @@ -427,6 +399,16 @@ export class PublicClientApplication { return this.browserStorage.getItem(BrowserConstants.INTERACTION_STATUS_KEY) === BrowserConstants.INTERACTION_IN_PROGRESS_VALUE; } + private preflightRequest(): void { + // block the reload if it occurred inside a hidden iframe + BrowserUtils.blockReloadInHiddenIframes(); + + // Check if interaction is in progress. Throw error if true. + if (this.interactionInProgress()) { + throw BrowserAuthError.createInteractionInProgressError(); + } + } + /** * Helper to remove interaction status and remove tempoarary request data. */ diff --git a/lib/msal-browser/test/app/PublicClientApplication.spec.ts b/lib/msal-browser/test/app/PublicClientApplication.spec.ts index 1007faa742..a567b0ca27 100644 --- a/lib/msal-browser/test/app/PublicClientApplication.spec.ts +++ b/lib/msal-browser/test/app/PublicClientApplication.spec.ts @@ -276,18 +276,10 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { describe("loginRedirect", () => { - it("loginRedirect throws an error if authCallback is not set", () => { - expect(() => pca.loginRedirect({})).to.throw(BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.desc); - expect(() => pca.loginRedirect({})).to.throw(BrowserConfigurationAuthError); - }); - it("loginRedirect throws an error if interaction is currently in progress", async () => { - await pca.handleRedirectCallback((authErr: AuthError, response: AuthResponse) => { - expect(authErr instanceof BrowserAuthError).to.be.true; - expect(authErr.errorMessage).to.be.eq(BrowserAuthErrorMessage.interactionInProgress.desc); - }); window.sessionStorage.setItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${BrowserConstants.INTERACTION_STATUS_KEY}`, BrowserConstants.INTERACTION_IN_PROGRESS_VALUE); - pca.loginRedirect({}); + expect(() => pca.loginRedirect({})).to.throw(BrowserAuthErrorMessage.interactionInProgress.desc); + expect(() => pca.loginRedirect({})).to.throw(BrowserAuthError); }); it("loginRedirect navigates to created login url", async () => { @@ -324,18 +316,10 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { describe("acquireTokenRedirect", () => { - it("acquireTokenRedirect throws an error if authCallback is not set", () => { - expect(() => pca.acquireTokenRedirect({})).to.throw(BrowserConfigurationAuthErrorMessage.noRedirectCallbacksSet.desc); - expect(() => pca.acquireTokenRedirect({})).to.throw(BrowserConfigurationAuthError); - }); - it("acquireTokenRedirect throws an error if interaction is currently in progress", async () => { - await pca.handleRedirectCallback((authErr: AuthError, response: AuthResponse) => { - expect(authErr instanceof BrowserAuthError).to.be.true; - expect(authErr.errorMessage).to.be.eq(BrowserAuthErrorMessage.interactionInProgress.desc); - }); window.sessionStorage.setItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${BrowserConstants.INTERACTION_STATUS_KEY}`, BrowserConstants.INTERACTION_IN_PROGRESS_VALUE); - pca.acquireTokenRedirect({}); + expect(() => pca.acquireTokenRedirect({})).to.throw(BrowserAuthErrorMessage.interactionInProgress.desc); + expect(() => pca.acquireTokenRedirect({})).to.throw(BrowserAuthError); }); it("acquireTokenRedirect navigates to created login url", async () => { From 876a49e4d1915f3e35550b5ca5cd6c115c3b41e9 Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Fri, 10 Apr 2020 11:25:53 -0700 Subject: [PATCH 2/8] Update PublicClientApplication.ts --- lib/msal-browser/src/app/PublicClientApplication.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index 920384956c..66ba5c86e7 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -89,6 +89,7 @@ export class PublicClientApplication { storageInterface: this.browserStorage }); + // Check for hash and save response promise this.tokenExchangePromise = this.handleRedirectResponse(); } From feef7e9ccdf8fe52a50eff77c5f642211a0daec6 Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Fri, 10 Apr 2020 11:30:29 -0700 Subject: [PATCH 3/8] Update PublicClientApplication.ts --- lib/msal-browser/src/app/PublicClientApplication.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index 66ba5c86e7..2575c0dddb 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -96,8 +96,7 @@ export class PublicClientApplication { // #region Redirect Flow /** - * Set the callback functions for the redirect flow to send back the success or error object, and process - * any redirect-related data. + * Process any redirect-related data and send back the success or error object. * IMPORTANT: Please do not use this function when using the popup APIs, as it may break the response handling * in the main window. * @@ -393,13 +392,16 @@ export class PublicClientApplication { // #region Helpers /** - * Helper to check whether interaction is in progress + * Helper to check whether interaction is in progress. */ private interactionInProgress(): boolean { // Check whether value in cache is present and equal to expected value return this.browserStorage.getItem(BrowserConstants.INTERACTION_STATUS_KEY) === BrowserConstants.INTERACTION_IN_PROGRESS_VALUE; } + /** + * Helper to validate app environment before making a request. + */ private preflightRequest(): void { // block the reload if it occurred inside a hidden iframe BrowserUtils.blockReloadInHiddenIframes(); From 692cec80014452dd4140469b025aec5daec6f77c Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Wed, 15 Apr 2020 11:42:02 -0700 Subject: [PATCH 4/8] Adding typedoc for ssoSilent --- .../src/app/PublicClientApplication.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index 2575c0dddb..b3bc563955 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -291,6 +291,22 @@ export class PublicClientApplication { // #region Silent Flow + /** + * This function uses a hidden iframe to fetch an authorization code from the eSTS. There are cases where this may not work: + * - Any browser using a form of Intelligent Tracking Prevention + * - If there is not an established session with the service + * + * In these cases, the request must be done inside a popup or full frame redirect. + * + * For the cases where interaction is required, you cannot send a request with prompt=none. + * + * If your refresh token has expired, you can use this function to fetch a new set of tokens silently as long as + * you session on the server still exists. + * @param {@link AuthenticationParameters} + * + * To renew idToken, please pass clientId as the only scope in the Authentication Parameters. + * @returns {Promise.} - a promise that is fulfilled when this function has completed, or rejected if an error was raised. Returns the {@link AuthResponse} object + */ async ssoSilent(request: AuthenticationParameters): Promise { // block the reload if it occurred inside a hidden iframe BrowserUtils.blockReloadInHiddenIframes(); From 8593970451f2465c3c80e9b67071e836a1c34b04 Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Wed, 15 Apr 2020 12:03:40 -0700 Subject: [PATCH 5/8] Adding check to make sure we only navigate when necessary --- lib/msal-browser/src/app/Configuration.ts | 4 ++-- lib/msal-browser/src/app/PublicClientApplication.ts | 3 ++- lib/msal-browser/src/interaction_handler/RedirectHandler.ts | 2 +- lib/msal-browser/src/utils/BrowserUtils.ts | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/msal-browser/src/app/Configuration.ts b/lib/msal-browser/src/app/Configuration.ts index 47f8822538..1e5c0e3d2e 100644 --- a/lib/msal-browser/src/app/Configuration.ts +++ b/lib/msal-browser/src/app/Configuration.ts @@ -60,8 +60,8 @@ export type Configuration = { const DEFAULT_AUTH_OPTIONS: BrowserAuthOptions = { clientId: "", authority: null, - redirectUri: () => BrowserUtils.getDefaultRedirectUri(), - postLogoutRedirectUri: () => BrowserUtils.getDefaultRedirectUri(), + redirectUri: () => BrowserUtils.getCurrentUri(), + postLogoutRedirectUri: () => BrowserUtils.getCurrentUri(), navigateToLoginRequestUrl: true }; diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index b3bc563955..2c9ba05800 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -136,11 +136,12 @@ export class PublicClientApplication { // Returned from authority using redirect - need to perform navigation before processing response this.browserStorage.setItem(TemporaryCacheKeys.URL_HASH, hash); const loginRequestUrl = this.browserStorage.getItem(TemporaryCacheKeys.ORIGIN_URI); + const currentUrl = BrowserUtils.getCurrentUri(); if (StringUtils.isEmpty(loginRequestUrl) || loginRequestUrl === "null") { // Redirect to home page if login request url is null (real null or the string null) this.authModule.logger.warning("Unable to get valid login request url from cache, redirecting to home page"); BrowserUtils.navigateWindow("/", true); - } else { + } else if (currentUrl !== loginRequestUrl) { BrowserUtils.navigateWindow(loginRequestUrl, true); } return null; diff --git a/lib/msal-browser/src/interaction_handler/RedirectHandler.ts b/lib/msal-browser/src/interaction_handler/RedirectHandler.ts index a06df03b25..31e79a52b8 100644 --- a/lib/msal-browser/src/interaction_handler/RedirectHandler.ts +++ b/lib/msal-browser/src/interaction_handler/RedirectHandler.ts @@ -18,7 +18,7 @@ export class RedirectHandler extends InteractionHandler { // Navigate if valid URL if (!StringUtils.isEmpty(requestUrl)) { // Set interaction status in the library. - this.browserStorage.setItem(TemporaryCacheKeys.ORIGIN_URI, window.location.href); + this.browserStorage.setItem(TemporaryCacheKeys.ORIGIN_URI, BrowserUtils.getCurrentUri()); this.browserStorage.setItem(BrowserConstants.INTERACTION_STATUS_KEY, BrowserConstants.INTERACTION_IN_PROGRESS_VALUE); this.authModule.logger.infoPii("Navigate to:" + requestUrl); const isIframedApp = BrowserUtils.isInIframe(); diff --git a/lib/msal-browser/src/utils/BrowserUtils.ts b/lib/msal-browser/src/utils/BrowserUtils.ts index 6d47682c7a..3b25351288 100644 --- a/lib/msal-browser/src/utils/BrowserUtils.ts +++ b/lib/msal-browser/src/utils/BrowserUtils.ts @@ -46,7 +46,7 @@ export class BrowserUtils { /** * Returns current window URL as redirect uri */ - static getDefaultRedirectUri(): string { + static getCurrentUri(): string { return window.location.href.split("?")[0].split("#")[0]; } From 1e9198a24de149d9376badbb31eb5596670ed978 Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Wed, 15 Apr 2020 12:30:06 -0700 Subject: [PATCH 6/8] Update PublicClientApplication.ts --- lib/msal-browser/src/app/PublicClientApplication.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index 2c9ba05800..a6caf68b00 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -142,7 +142,12 @@ export class PublicClientApplication { this.authModule.logger.warning("Unable to get valid login request url from cache, redirecting to home page"); BrowserUtils.navigateWindow("/", true); } else if (currentUrl !== loginRequestUrl) { + // Navigate to target url BrowserUtils.navigateWindow(loginRequestUrl, true); + } else { + // We don't need to navigate - check for hash and prepare to process + BrowserUtils.clearHash(); + return this.handleHash(hash); } return null; } From 430102f5de85614030e4c9301fc14e0044b54e3a Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Wed, 15 Apr 2020 12:49:10 -0700 Subject: [PATCH 7/8] Adding separate check for when loginRequesturi is the same as current uri --- .../src/app/PublicClientApplication.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/msal-browser/src/app/PublicClientApplication.ts b/lib/msal-browser/src/app/PublicClientApplication.ts index a6caf68b00..8a5889ac09 100644 --- a/lib/msal-browser/src/app/PublicClientApplication.ts +++ b/lib/msal-browser/src/app/PublicClientApplication.ts @@ -132,22 +132,31 @@ export class PublicClientApplication { const { location: { hash } } = window; const cachedHash = this.browserStorage.getItem(TemporaryCacheKeys.URL_HASH); const isResponseHash = UrlString.hashContainsKnownProperties(hash); + + const loginRequestUrl = this.browserStorage.getItem(TemporaryCacheKeys.ORIGIN_URI); + const currentUrl = BrowserUtils.getCurrentUri(); + if (loginRequestUrl === currentUrl) { + // We don't need to navigate - check for hash and prepare to process + if (isResponseHash) { + BrowserUtils.clearHash(); + return this.handleHash(hash); + } else { + // Loaded page with no valid hash - pass in the value retrieved from cache, or null/empty string + return this.handleHash(cachedHash); + } + } + if (this.config.auth.navigateToLoginRequestUrl && isResponseHash && !BrowserUtils.isInIframe()) { // Returned from authority using redirect - need to perform navigation before processing response this.browserStorage.setItem(TemporaryCacheKeys.URL_HASH, hash); - const loginRequestUrl = this.browserStorage.getItem(TemporaryCacheKeys.ORIGIN_URI); - const currentUrl = BrowserUtils.getCurrentUri(); + if (StringUtils.isEmpty(loginRequestUrl) || loginRequestUrl === "null") { // Redirect to home page if login request url is null (real null or the string null) this.authModule.logger.warning("Unable to get valid login request url from cache, redirecting to home page"); BrowserUtils.navigateWindow("/", true); - } else if (currentUrl !== loginRequestUrl) { + } else { // Navigate to target url BrowserUtils.navigateWindow(loginRequestUrl, true); - } else { - // We don't need to navigate - check for hash and prepare to process - BrowserUtils.clearHash(); - return this.handleHash(hash); } return null; } From 1ae56ed67c5ccd5cfa01e20c6ce045722aafc9f4 Mon Sep 17 00:00:00 2001 From: Prithvi Kanherkar Date: Wed, 22 Apr 2020 16:04:52 -0700 Subject: [PATCH 8/8] Fixing unit tests --- .../test/app/PublicClientApplication.spec.ts | 32 +++++++++---------- .../test/utils/BrowserUtils.spec.ts | 4 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/msal-browser/test/app/PublicClientApplication.spec.ts b/lib/msal-browser/test/app/PublicClientApplication.spec.ts index e39cba0072..a357422b70 100644 --- a/lib/msal-browser/test/app/PublicClientApplication.spec.ts +++ b/lib/msal-browser/test/app/PublicClientApplication.spec.ts @@ -58,6 +58,22 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { expect(pca).to.be.not.null; expect(pca instanceof PublicClientApplication).to.be.true; }); + + it("navigates and caches hash if navigateToLoginRequestUri is true", () => { + window.location.hash = TEST_HASHES.TEST_SUCCESS_CODE_HASH; + window.sessionStorage.setItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${TemporaryCacheKeys.ORIGIN_URI}`, TEST_URIS.TEST_REDIR_URI); + sinon.stub(BrowserUtils, "getCurrentUri").returns("notAUri"); + sinon.stub(BrowserUtils, "navigateWindow").callsFake((urlNavigate: string, noHistory?: boolean) => { + expect(noHistory).to.be.true; + expect(urlNavigate).to.be.eq(TEST_URIS.TEST_REDIR_URI); + }); + pca = new PublicClientApplication({ + auth: { + clientId: TEST_CONFIG.MSAL_CLIENT_ID + } + }); + expect(window.sessionStorage.getItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${TemporaryCacheKeys.URL_HASH}`)).to.be.eq(TEST_HASHES.TEST_SUCCESS_CODE_HASH); + }); }); describe("Redirect Flow Unit tests", () => { @@ -75,22 +91,6 @@ describe("PublicClientApplication.ts Class Unit Tests", () => { expect(window.sessionStorage.length).to.be.eq(0); }); - it("navigates and caches hash if navigateToLoginRequestUri is true", () => { - window.location.hash = TEST_HASHES.TEST_SUCCESS_CODE_HASH; - window.sessionStorage.setItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${TemporaryCacheKeys.ORIGIN_URI}`, TEST_URIS.TEST_REDIR_URI); - sinon.stub(BrowserUtils, "navigateWindow").callsFake((urlNavigate: string, noHistory?: boolean) => { - expect(noHistory).to.be.true; - expect(urlNavigate).to.be.eq(TEST_URIS.TEST_REDIR_URI); - }); - pca = new PublicClientApplication({ - auth: { - clientId: TEST_CONFIG.MSAL_CLIENT_ID - } - }); - pca.handleRedirectCallback(authCallback); - expect(window.sessionStorage.getItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${TemporaryCacheKeys.URL_HASH}`)).to.be.eq(TEST_HASHES.TEST_SUCCESS_CODE_HASH); - }); - it("gets hash from cache and processes response", async () => { const b64Encode = new Base64Encode(); window.sessionStorage.setItem(`${Constants.CACHE_PREFIX}.${TEST_CONFIG.MSAL_CLIENT_ID}.${TemporaryCacheKeys.ORIGIN_URI}`, TEST_URIS.TEST_REDIR_URI); diff --git a/lib/msal-browser/test/utils/BrowserUtils.spec.ts b/lib/msal-browser/test/utils/BrowserUtils.spec.ts index 2b13851767..854bb8c0f9 100644 --- a/lib/msal-browser/test/utils/BrowserUtils.spec.ts +++ b/lib/msal-browser/test/utils/BrowserUtils.spec.ts @@ -68,8 +68,8 @@ describe("BrowserUtils.ts Function Unit Tests", () => { expect(BrowserUtils.isInIframe()).to.be.true; }); - it("getDefaultRedirectUri returns current location uri of browser", () => { - expect(BrowserUtils.getDefaultRedirectUri()).to.be.eq(TEST_URIS.TEST_REDIR_URI); + it("getCurrentUri() returns current location uri of browser", () => { + expect(BrowserUtils.getCurrentUri()).to.be.eq(TEST_URIS.TEST_REDIR_URI); }); it("getBrowserNetworkClient() returns fetch client if available", () => {