-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Core Library
MSAL.js (@azure/msal-browser)
Wrapper Library
MSAL Angular (@azure/msal-angular)
Public or Confidential Client?
Public
Description
I am submitting this because I don't think that issue #8109 was fully addresses.
I have an Angular SPA that is using Playwright for e2e testing. This project uses the latest version of the libraries from this repo. With the latest versions of the libraries the Playwright Testing Samples no longer work. This is because the schema used for caching tokens has diverged between the browser and node libraires in the latest versions and these samples use an older version of the browser library. I can successfully use the node library in Playwright during test setup to request tokens using the ROPC flow, save them and inject them into sessionStorage for each test. The problem is the browser library doesn't recognize the schema that was used to create the cache keys by the node library so it thinks there are no accounts loaded and the app gets redirected to the IDP during the tests.
The solution to this is:
- use a POST request to the token endpoint to get the tokens and manually creating the cache keys by 'copying' code that isn't part of the public API. This is fragile but does work.
- Redirect to the IDP during test setup in the browser to login and after redirect back to the application, get the tokens from browser storage and save them for use in tests. This also works but I am now using a UI that I don't have control over and can change (or MFA could be enforced on all accounts in the future) which can cause my tests to break. I am also now making a network request that my tests depend on and can fail.
The browser library has a method (loadExternalTokens) for situations like this but of course it does not work in Playwright (it works in Cypress) because test setup in Playwright doesn't run in the browser.
My request is that either the node library token cache schema is always kept in sync with the browser library or there is an API introduced to the browser library that doesn't require a browser environment and that, given a response from the token endpoint (or a mock response) will create a cacheable key/value data structure with the correct schema that we can save and load into browser storage when needed.