Skip to content

Commit be0aa70

Browse files
author
Prithvi Kanherkar
committed
Revert "Merge branch 'dev' into add-beachball-config"
This reverts commit a725470, reversing changes made to b9626a5.
1 parent 58ec8e5 commit be0aa70

38 files changed

+125
-677
lines changed

experimental/msal-react-native-android-poc/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/msal-browser/src/app/PublicClientApplication.ts

+34-72
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ import {
2828
SilentFlowClient,
2929
EndSessionRequest,
3030
BaseAuthRequest,
31-
Logger,
32-
ServerAuthorizationCodeResponse
31+
Logger
3332
} from "@azure/msal-common";
3433
import { buildConfiguration, Configuration } from "../config/Configuration";
3534
import { BrowserStorage } from "../cache/BrowserStorage";
@@ -38,14 +37,13 @@ import { RedirectHandler } from "../interaction_handler/RedirectHandler";
3837
import { PopupHandler } from "../interaction_handler/PopupHandler";
3938
import { SilentHandler } from "../interaction_handler/SilentHandler";
4039
import { BrowserAuthError } from "../error/BrowserAuthError";
41-
import { BrowserConstants, TemporaryCacheKeys, DEFAULT_REQUEST, InteractionType } from "../utils/BrowserConstants";
40+
import { BrowserConstants, TemporaryCacheKeys, DEFAULT_REQUEST } from "../utils/BrowserConstants";
4241
import { BrowserUtils } from "../utils/BrowserUtils";
4342
import { version } from "../../package.json";
4443
import { IPublicClientApplication } from "./IPublicClientApplication";
4544
import { RedirectRequest } from "../request/RedirectRequest";
4645
import { PopupRequest } from "../request/PopupRequest";
4746
import { SilentRequest } from "../request/SilentRequest";
48-
import { BrowserProtocolUtils, BrowserStateObject } from "../utils/BrowserProtocolUtils";
4947

5048
/**
5149
* The PublicClientApplication class is the object exposed by the library to perform authentication and authorization functions in Single Page Applications
@@ -134,76 +132,45 @@ export class PublicClientApplication implements IPublicClientApplication {
134132
* - if true, performs logic to cache and navigate
135133
* - if false, handles hash string and parses response
136134
*/
137-
private async handleRedirectResponse(): Promise<AuthenticationResult | null> {
138-
const responseHash = this.getRedirectResponseHash();
139-
if (!responseHash) {
140-
// Not a recognized server response hash or hash not associated with a redirect request
141-
return null;
142-
}
143-
144-
// If navigateToLoginRequestUrl is true, get the url where the redirect request was initiated
135+
private async handleRedirectResponse(): Promise<AuthenticationResult> {
136+
// Get current location hash from window or cache.
137+
const { location: { hash } } = window;
138+
const cachedHash = this.browserStorage.getItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH), CacheSchemaType.TEMPORARY) as string;
139+
const isResponseHash = UrlString.hashContainsKnownProperties(hash);
145140
const loginRequestUrl = this.browserStorage.getItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.ORIGIN_URI), CacheSchemaType.TEMPORARY) as string;
146-
const loginRequestUrlNormalized = UrlString.removeHashFromUrl(loginRequestUrl || "");
147-
const currentUrlNormalized = UrlString.removeHashFromUrl(window.location.href);
148141

142+
const currentUrlNormalized = UrlString.removeHashFromUrl(window.location.href);
143+
const loginRequestUrlNormalized = UrlString.removeHashFromUrl(loginRequestUrl || "");
149144
if (loginRequestUrlNormalized === currentUrlNormalized && this.config.auth.navigateToLoginRequestUrl) {
150-
if (loginRequestUrl.indexOf("#") > -1) {
151-
// Replace current hash with non-msal hash, if present
152-
BrowserUtils.replaceHash(loginRequestUrl);
153-
}
154145
// We are on the page we need to navigate to - handle hash
155-
return this.handleHash(responseHash);
156-
} else if (!this.config.auth.navigateToLoginRequestUrl) {
157-
return this.handleHash(responseHash);
158-
} else if (!BrowserUtils.isInIframe()) {
146+
// Replace current hash with non-msal hash, if present
147+
BrowserUtils.replaceHash(loginRequestUrl);
148+
return this.handleHash(isResponseHash ? hash : cachedHash);
149+
}
150+
151+
if (!this.config.auth.navigateToLoginRequestUrl) {
152+
// We don't need to navigate - handle hash
153+
BrowserUtils.clearHash();
154+
return this.handleHash(isResponseHash ? hash : cachedHash);
155+
}
156+
157+
if (isResponseHash && !BrowserUtils.isInIframe()) {
159158
// Returned from authority using redirect - need to perform navigation before processing response
160-
// Cache the hash to be retrieved after the next redirect
161159
const hashKey = this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH);
162-
this.browserStorage.setItem(hashKey, responseHash, CacheSchemaType.TEMPORARY);
163-
if (!loginRequestUrl || loginRequestUrl === "null") {
160+
this.browserStorage.setItem(hashKey, hash, CacheSchemaType.TEMPORARY);
161+
if (StringUtils.isEmpty(loginRequestUrl) || loginRequestUrl === "null") {
164162
// Redirect to home page if login request url is null (real null or the string null)
165-
const homepage = BrowserUtils.getHomepage();
166-
// Cache the homepage under ORIGIN_URI to ensure cached hash is processed on homepage
167-
this.browserStorage.setItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.ORIGIN_URI), homepage, CacheSchemaType.TEMPORARY);
168163
this.logger.warning("Unable to get valid login request url from cache, redirecting to home page");
169-
BrowserUtils.navigateWindow(homepage, true);
164+
BrowserUtils.navigateWindow("/", true);
170165
} else {
171-
// Navigate to page that initiated the redirect request
166+
// Navigate to target url
172167
BrowserUtils.navigateWindow(loginRequestUrl, true);
173168
}
174169
}
175170

176171
return null;
177172
}
178173

179-
/**
180-
* Gets the response hash for a redirect request
181-
* Returns null if interactionType in the state value is not "redirect" or the hash does not contain known properties
182-
* @returns {string}
183-
*/
184-
private getRedirectResponseHash(): string {
185-
// Get current location hash from window or cache.
186-
const { location: { hash } } = window;
187-
const isResponseHash = UrlString.hashContainsKnownProperties(hash);
188-
const cachedHash = this.browserStorage.getItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH), CacheSchemaType.TEMPORARY) as string;
189-
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));
190-
191-
const responseHash = isResponseHash ? hash : cachedHash;
192-
if (responseHash) {
193-
// Deserialize hash fragment response parameters.
194-
const serverParams: ServerAuthorizationCodeResponse = UrlString.getDeserializedHash(responseHash);
195-
const platformStateObj: BrowserStateObject = BrowserProtocolUtils.extractBrowserRequestState(this.browserCrypto, serverParams.state);
196-
if (platformStateObj.interactionType !== InteractionType.REDIRECT) {
197-
return null;
198-
} else {
199-
BrowserUtils.clearHash();
200-
return responseHash;
201-
}
202-
}
203-
204-
return null;
205-
}
206-
207174
/**
208175
* Checks if hash exists and handles in window.
209176
* @param responseHash
@@ -248,7 +215,7 @@ export class PublicClientApplication implements IPublicClientApplication {
248215
async acquireTokenRedirect(request: RedirectRequest): Promise<void> {
249216
try {
250217
// Preflight request
251-
const validRequest: AuthorizationUrlRequest = this.preflightInteractiveRequest(request, InteractionType.REDIRECT);
218+
const validRequest: AuthorizationUrlRequest = this.preflightInteractiveRequest(request);
252219

253220
// Create auth code request and generate PKCE params
254221
const authCodeRequest: AuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(validRequest);
@@ -295,7 +262,7 @@ export class PublicClientApplication implements IPublicClientApplication {
295262
async acquireTokenPopup(request: PopupRequest): Promise<AuthenticationResult> {
296263
try {
297264
// Preflight request
298-
const validRequest: AuthorizationUrlRequest = this.preflightInteractiveRequest(request, InteractionType.POPUP);
265+
const validRequest: AuthorizationUrlRequest = this.preflightInteractiveRequest(request);
299266

300267
// Create auth code request and generate PKCE params
301268
const authCodeRequest: AuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(validRequest);
@@ -366,7 +333,7 @@ export class PublicClientApplication implements IPublicClientApplication {
366333
const silentRequest: AuthorizationUrlRequest = this.initializeAuthorizationRequest({
367334
...request,
368335
prompt: PromptValue.NONE
369-
}, InteractionType.SILENT);
336+
});
370337

371338
// Create auth code request and generate PKCE params
372339
const authCodeRequest: AuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(silentRequest);
@@ -416,7 +383,7 @@ export class PublicClientApplication implements IPublicClientApplication {
416383
...silentRequest,
417384
redirectUri: request.redirectUri,
418385
prompt: PromptValue.NONE
419-
}, InteractionType.SILENT);
386+
});
420387

421388
// Create auth code request and generate PKCE params
422389
const authCodeRequest: AuthorizationCodeRequest = await this.initializeAuthorizationCodeRequest(silentAuthUrlRequest);
@@ -599,7 +566,7 @@ export class PublicClientApplication implements IPublicClientApplication {
599566
/**
600567
* Helper to validate app environment before making a request.
601568
*/
602-
private preflightInteractiveRequest(request: RedirectRequest|PopupRequest, interactionType: InteractionType): AuthorizationUrlRequest {
569+
private preflightInteractiveRequest(request: RedirectRequest|PopupRequest): AuthorizationUrlRequest {
603570
// block the reload if it occurred inside a hidden iframe
604571
BrowserUtils.blockReloadInHiddenIframes();
605572

@@ -608,7 +575,7 @@ export class PublicClientApplication implements IPublicClientApplication {
608575
throw BrowserAuthError.createInteractionInProgressError();
609576
}
610577

611-
return this.initializeAuthorizationRequest(request, interactionType);
578+
return this.initializeAuthorizationRequest(request);
612579
}
613580

614581
/**
@@ -644,7 +611,7 @@ export class PublicClientApplication implements IPublicClientApplication {
644611
* Helper to initialize required request parameters for interactive APIs and ssoSilent()
645612
* @param request
646613
*/
647-
private initializeAuthorizationRequest(request: AuthorizationUrlRequest|RedirectRequest|PopupRequest, interactionType: InteractionType): AuthorizationUrlRequest {
614+
private initializeAuthorizationRequest(request: AuthorizationUrlRequest|RedirectRequest|PopupRequest): AuthorizationUrlRequest {
648615
let validatedRequest: AuthorizationUrlRequest = {
649616
...request
650617
};
@@ -664,20 +631,15 @@ export class PublicClientApplication implements IPublicClientApplication {
664631
}
665632
}
666633

667-
const browserState: BrowserStateObject = {
668-
interactionType: interactionType
669-
};
670-
671634
validatedRequest.state = ProtocolUtils.setRequestState(
672-
this.browserCrypto,
673635
(request && request.state) || "",
674-
browserState
636+
this.browserCrypto
675637
);
676638

677639
if (StringUtils.isEmpty(validatedRequest.nonce)) {
678640
validatedRequest.nonce = this.browserCrypto.createNewGuid();
679641
}
680-
642+
681643
validatedRequest.responseMode = ResponseMode.FRAGMENT;
682644

683645
validatedRequest = {

lib/msal-browser/src/interaction_handler/RedirectHandler.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ export class RedirectHandler extends InteractionHandler {
6565
this.authCodeRequest = this.browserStorage.getCachedRequest(requestState, browserCrypto);
6666
this.authCodeRequest.code = authCode;
6767

68+
// Hash was processed successfully - remove from cache
69+
this.browserStorage.removeItem(this.browserStorage.generateCacheKey(TemporaryCacheKeys.URL_HASH));
70+
6871
// Acquire token with retrieved code.
6972
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, cachedNonce, requestState);
70-
7173
this.browserStorage.cleanRequest();
7274
return tokenResponse;
7375
}

lib/msal-browser/src/utils/BrowserConstants.ts

-9
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,6 @@ export enum TemporaryCacheKeys {
5353
SCOPES = "scopes"
5454
}
5555

56-
/**
57-
* Interaction type of the API - used for state and telemetry
58-
*/
59-
export enum InteractionType {
60-
REDIRECT = "redirect",
61-
POPUP = "popup",
62-
SILENT = "silent"
63-
}
64-
6556
export const DEFAULT_REQUEST: AuthorizationUrlRequest = {
6657
scopes: [Constants.OPENID_SCOPE, Constants.PROFILE_SCOPE]
6758
};

lib/msal-browser/src/utils/BrowserProtocolUtils.ts

-32
This file was deleted.

lib/msal-browser/src/utils/BrowserUtils.ts

-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ export class BrowserUtils {
6060
return window.location.href.split("?")[0].split("#")[0];
6161
}
6262

63-
/**
64-
* Gets the homepage url for the current window location.
65-
*/
66-
static getHomepage(): string {
67-
const currentUrl = new UrlString(window.location.href);
68-
const urlComponents = currentUrl.getUrlComponents();
69-
return `${urlComponents.Protocol}//${urlComponents.HostNameAndPort}/`;
70-
}
71-
7263
/**
7364
* Returns best compatible network client object.
7465
*/

0 commit comments

Comments
 (0)