-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
[msal-common]Combine Request
module for node
and browser
components
#1682
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
07859c9
Code Changes for combining requests
sameerag bf6bb63
delete "resource" references
sameerag d76361d
Merge branch 'dev' into msal-node-merge-request
sameerag 3dfdd1f
Changing request type
sameerag 7647637
Adding changes for request
pkanher617 3891c17
Finished changes to msal-browser to support msal-common request changes
pkanher617 4926cd7
Merge branch 'dev' into msal-node-merge-request
pkanher617 b0b086e
Merge branch 'msal-node-cache-response' into msal-node-merge-request
sameerag afd3b25
For msal-node compat, will make the needed changes for 'Prompt` later
sameerag 50b4356
Cleaning up code, adding feedback from PR
pkanher617 202ec45
Merge branch 'dev' into msal-node-merge-request
05c6c64
Fixed tests in msal-common, working on msal-browser
e40fc7e
Fixing tests for browser, not done yet
d5da04a
All builds passing
163a853
Merge branch 'dev' into msal-node-merge-request
bc9bd3f
Fix linting
1261566
All unit tests passing
8110eba
Merge branch 'dev' into msal-node-merge-request
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,10 @@ | |
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
import { StringUtils, TemporaryCacheKeys, TokenResponse } from "@azure/msal-common"; | ||
import { StringUtils, TokenResponse, AuthorizationCodeRequest, ICrypto, ProtocolUtils } from "@azure/msal-common"; | ||
import { InteractionHandler } from "./InteractionHandler"; | ||
import { BrowserAuthError } from "../error/BrowserAuthError"; | ||
import { BrowserConstants } from "../utils/BrowserConstants"; | ||
import { BrowserConstants, TemporaryCacheKeys } from "../utils/BrowserConstants"; | ||
import { BrowserUtils } from "../utils/BrowserUtils"; | ||
|
||
export class RedirectHandler extends InteractionHandler { | ||
|
@@ -14,12 +14,13 @@ export class RedirectHandler extends InteractionHandler { | |
* Redirects window to given URL. | ||
* @param urlNavigate | ||
*/ | ||
initiateAuthRequest(requestUrl: string): Window { | ||
initiateAuthRequest(requestUrl: string, authCodeRequest: AuthorizationCodeRequest, browserCrypto?: ICrypto): Window { | ||
// Navigate if valid URL | ||
if (!StringUtils.isEmpty(requestUrl)) { | ||
// Set interaction status in the library. | ||
this.browserStorage.setItem(TemporaryCacheKeys.ORIGIN_URI, BrowserUtils.getCurrentUri()); | ||
this.browserStorage.setItem(BrowserConstants.INTERACTION_STATUS_KEY, BrowserConstants.INTERACTION_IN_PROGRESS_VALUE); | ||
this.browserStorage.cacheCodeRequest(authCodeRequest, browserCrypto); | ||
this.authModule.logger.infoPii("Navigate to:" + requestUrl); | ||
const isIframedApp = BrowserUtils.isInIframe(); | ||
if (isIframedApp) { | ||
|
@@ -41,19 +42,34 @@ export class RedirectHandler extends InteractionHandler { | |
* Handle authorization code response in the window. | ||
* @param hash | ||
*/ | ||
async handleCodeResponse(locationHash: string): Promise<TokenResponse> { | ||
async handleCodeResponse(locationHash: string, browserCrypto?: ICrypto): Promise<TokenResponse> { | ||
// Check that location hash isn't empty. | ||
if (StringUtils.isEmpty(locationHash)) { | ||
throw BrowserAuthError.createEmptyHashError(locationHash); | ||
} | ||
|
||
// Interaction is completed - remove interaction status. | ||
this.browserStorage.removeItem(BrowserConstants.INTERACTION_STATUS_KEY); | ||
|
||
// Get cached items | ||
const requestState = this.browserStorage.getItem(TemporaryCacheKeys.REQUEST_STATE); | ||
const cachedNonceKey = this.browserStorage.generateNonceKey(requestState); | ||
const cachedNonce = this.browserStorage.getItem(cachedNonceKey); | ||
this.authCodeRequest = this.browserStorage.getCachedRequest(requestState, browserCrypto); | ||
|
||
// Handle code response. | ||
const codeResponse = this.authModule.handleFragmentResponse(locationHash); | ||
const authCode = this.authModule.handleFragmentResponse(locationHash, requestState); | ||
this.authCodeRequest.code = authCode; | ||
|
||
// Hash was processed successfully - remove from cache | ||
this.browserStorage.removeItem(TemporaryCacheKeys.URL_HASH); | ||
|
||
// Extract user state. | ||
const userState = ProtocolUtils.getUserRequestState(requestState); | ||
|
||
// Acquire token with retrieved code. | ||
return this.authModule.acquireToken(codeResponse); | ||
const tokenResponse = await this.authModule.acquireToken(this.authCodeRequest, userState, cachedNonce); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's discuss nonce, I wonder why this is not applicable to |
||
this.browserStorage.cleanRequest(); | ||
return tokenResponse; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this. All browser specific cache handling now is clearly demarcated between
msal-common
andmsal-browser