equinor / fusion-framework

Fusion Framework, built and maintained to Fusion Core
https://equinor.github.io/fusion-framework/
MIT License
8 stars 6 forks source link

MSAL - update module for to work with msal-browser 3 #1228

Open odinr opened 1 year ago

odinr commented 1 year ago

Microsoft has rewritten the interface for MSAL 🥺

see changes for msal-browser@3, more than 2k files changed 😓

the "main" change is that after creating a PublicClientApplication, the instance need to await initialization

Proposed changes:

proposed change will not affect any end-users (consumer of the package)

change logic from JiT to initialize clients in the module.initialize

https://github.com/equinor/fusion-framework/blob/eb86f1e7ede7da1df1605d41601b702c9087879a/packages/modules/msal/src/module.ts#L19-L28

--- a/packages/modules/msal/src/module.ts
+++ b/packages/modules/msal/src/modulets
@@ -19,9 +19,10 @@
initialize: async ({ config }) => {
+  const clients = await createAuthClients(config); // add function for resolving all provided clients 
+  const authProvider = new AuthProvider({clients});
-  const authProvider = new AuthProvider(config); 
    if (config.requiresAuth) {
        await authProvider.handleRedirect();
        if (!authProvider.defaultAccount) {
            await authProvider.login();
        }
    }
    return authProvider;
},

cause of error: https://github.com/equinor/fusion-framework/blob/eb86f1e7ede7da1df1605d41601b702c9087879a/packages/modules/msal/src/provider.ts#L70-L93 other:

PublicClientApplication.logger = PublicClientApplication.getLogger()
// TODO check if there is a better way to figure out the `request.origin`
PublicClientApplication.browserStorage = PublicClientApplication.getBrowserStorage();

see https://github.com/equinor/fusion-framework/pull/1167

odinr commented 1 year ago

we might be able to remove some code, since the package now provide:

this was "hacked" together with:

https://github.com/equinor/fusion-framework/blob/eb86f1e7ede7da1df1605d41601b702c9087879a/packages/modules/msal/src/client/client.ts#L60-L66

odinr commented 1 year ago

check if there is a feature to replace:

https://github.com/equinor/fusion-framework/blob/eb86f1e7ede7da1df1605d41601b702c9087879a/packages/modules/msal/src/client/client.ts#L68-L75