You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We develop a react app bith a node js backend which do handle the authentication using msal-node. As our app is deployed to a serverless infra we want to implement a persistant cache in our db instead as suggested per the documentation.
We first found several links to this sample and wanted to reproduce the implementation of the persistant cache plugin. As things were not working due to outdated code, we then stumbled upon this beta project, which is more complex than what we need (we only needed the cache part).
This is part of the code we use (and is working)
import*asmsalfrom'@azure/msal-node';constMsIdExpress=require('microsoft-identity-express');//we get typescrit errors when using importconstcca=newmsal.ConfidentialClientApplication(AADConfig);constAADConfig={auth: {clientId: process.env.AAD_CLIENT_ID,authority: `https://login.microsoftonline.com/${process.env.AAD_TENANT_ID}`,clientSecret: process.env.AAD_CLIENT_SECRET,},system: {loggerOptions: {loggerCallback(loglevel,message,containsPii){console.log(message);},piiLoggingEnabled: false,logLevel: msal.LogLevel?.Error||0,},},};constappSettings={appCredentials: {clientId: process.env.AAD_CLIENT_ID,// Application (client) ID on Azure ADtenantId: process.env.AAD_TENANT_ID,// alt. "common" "organizations" "consumers"clientSecret: process.env.AAD_CLIENT_SECRET,// alt. client certificate or key vault credential},}asAppSettings;constmsid=newMsIdExpress.MsalWebApiAuthClient(appSettings,AADConfig);msid.msalClient=cca;app.use((req,res,next)=>{const{ homeaccountid }=req.headers;if(homeaccountid){constcache=initCache(homeaccountid);msid.msalClient.tokenCache.persistence=cache;msid.msalConfig.cache={cachePlugin: cache};}next();});
Is the microsoft-identity-express package really needed to do persistent caching? It seems to us that we only use it to extend msal-node base classes and expose the cache part so that it can be replaced by current user cache at request time. Did we miss something?
Edit : we also found this part of the doc which suggest that the configuration options for ClientApplication can be set with constuctor or edited later but we didn't find method to do so (or public properties that could be edited).
Edit 2 : microsoft-identity-express won't install on our CI/CD so we switched to creating a msal client at request time instead of app start.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
We develop a react app bith a node js backend which do handle the authentication using msal-node. As our app is deployed to a serverless infra we want to implement a persistant cache in our db instead as suggested per the documentation.
We first found several links to this sample and wanted to reproduce the implementation of the persistant cache plugin. As things were not working due to outdated code, we then stumbled upon this beta project, which is more complex than what we need (we only needed the cache part).
This is part of the code we use (and is working)
Is the
microsoft-identity-express
package really needed to do persistent caching? It seems to us that we only use it to extend msal-node base classes and expose the cache part so that it can be replaced by current user cache at request time. Did we miss something?Edit : we also found this part of the doc which suggest that the configuration options for
ClientApplication
can be set with constuctor or edited later but we didn't find method to do so (or public properties that could be edited).Edit 2 :
microsoft-identity-express
won't install on our CI/CD so we switched to creating a msal client at request time instead of app start.Beta Was this translation helpful? Give feedback.
All reactions