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

Throw when initialize has not been called #6233

Merged
merged 32 commits into from
Jul 26, 2023
Merged

Conversation

hectormmg
Copy link
Member

@hectormmg hectormmg commented Jul 12, 2023

This PR:

  • Replaces BrowserUtils.blockNativeBrokerCalledBeforeInitialize with BrowserUtils.blockCallsBeforeInitialize since now initialize call is required regardless of whether allowNativeBroker is enabled
  • Calls BrowserUtils.blockCallsBeforeInitialize in all public APIs related to token acquisition and accounts
  • Replaces BrowserAuthError.createNativeBrokerCalledBeforeInitialize() with BrowserAuthError.createUninitializedPublicClientApplication() and updates error message
  • Updates browser spec files to match new behavior

@github-actions github-actions bot added the msal-browser Related to msal-browser package label Jul 12, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2023

Codecov Report

Merging #6233 (bce4fb2) into dev (81d34b4) will increase coverage by 1.78%.
Report is 217 commits behind head on dev.
The diff coverage is 96.63%.

Flag Coverage Δ
msal-angular 96.73% <96.63%> (+0.22%) ⬆️
msal-browser 85.66% <ø> (-0.81%) ⬇️
msal-common ?
msal-core ?
msal-node ?
msal-node-extensions ?
msal-react 94.24% <ø> (-0.45%) ⬇️
node-token-validation ?
Files Changed Coverage Δ
...b/msal-browser/src/app/IPublicClientApplication.ts 43.75% <ø> (ø)
...ib/msal-browser/src/app/PublicClientApplication.ts 66.66% <ø> (-28.67%) ⬇️
...er/src/broker/nativeBroker/NativeMessageHandler.ts 86.29% <ø> (+0.33%) ⬆️
lib/msal-browser/src/cache/AsyncMemoryStorage.ts 80.76% <ø> (+2.99%) ⬆️
lib/msal-browser/src/cache/BrowserCacheManager.ts 90.18% <ø> (-1.54%) ⬇️
lib/msal-browser/src/cache/BrowserStorage.ts 87.50% <ø> (-3.41%) ⬇️
lib/msal-browser/src/cache/CryptoKeyStore.ts 80.00% <ø> (-3.34%) ⬇️
lib/msal-browser/src/cache/DatabaseStorage.ts 34.00% <ø> (-4.54%) ⬇️
lib/msal-browser/src/cache/MemoryStorage.ts 100.00% <ø> (ø)
lib/msal-browser/src/cache/TokenCache.ts 85.86% <ø> (+4.86%) ⬆️
... and 56 more

... and 168 files with indirect coverage changes

Copy link
Collaborator

@tnorling tnorling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good besides one minor comment, thanks for this!

Copy link
Member

@sameerag sameerag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not initialize ourselves by default instead of adding this check at a zillion places?

Copy link
Member

@sameerag sameerag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we sync up once before I approve this on why we chose not to initialize ourselves or if there is a better way to do this?

@hectormmg
Copy link
Member Author

Can we sync up once before I approve this on why we chose not to initialize ourselves or if there is a better way to do this?

There's not much we can do since initialize is async. We need these checks because someone could instantiate a PCA and start calling APIs without initializing.

Copy link
Member

@sameerag sameerag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, approving with suggestions to improve on this for the next major version. Also:
nit: Can we rename the function name to blockAPICallsBeforeInitialize()?

@github-actions github-actions bot added the samples Related to the samples apps for the library. label Jul 19, 2023
@github-actions github-actions bot added the msal-react Related to @azure/msal-react label Jul 25, 2023
@hectormmg hectormmg requested a review from shoatman July 25, 2023 23:40
Copy link
Contributor

@shoatman shoatman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@hectormmg hectormmg merged commit 26a8031 into dev Jul 26, 2023
33 of 42 checks passed
@hectormmg hectormmg deleted the throw-without-initialize branch July 26, 2023 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
msal-browser Related to msal-browser package msal-react Related to @azure/msal-react samples Related to the samples apps for the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants