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
Hi, I would like to get microsoft token using MSAL library and then send it to server, but the extension does not wait for events to finish. Can this be somehow achieved? I can create PR but I'm not sure if it makes sense for the library or how the solution should look like.
Hi, I'm afraid this is not currently possible. Naja relies on DOM's standard EventTarget for event dispatch, and that API is, unfortunately, synchronous.
But the before event contains all you need to recreate the request, and can be default-prevented to abort the request. You can use all this to fetch the token and dispatch the request manually afterwards:
exportclassTokenExtension{initialize(naja){this.naja=naja;naja.addEventListener('before',this.before.bind(this));}before(event){const{request, method, url, data, options}=event.detail;// if the token is already in options, set up the request and early-return to proceedif(options.msalToken){request.headers.set('X-Token',options.msalToken);return;}// call preventDefault() to abort current request processingevent.preventDefault();// fetch the token and rerun the request, passing the token in optionsfetch('https://microsoft.com').then((msalToken)=>this.naja.makeRequest(method,url,data,{...options, msalToken}));}}
Hi, I would like to get microsoft token using MSAL library and then send it to server, but the extension does not wait for events to finish. Can this be somehow achieved? I can create PR but I'm not sure if it makes sense for the library or how the solution should look like.
Simplified version of my usage would be:
I noticed similar point here #383 . Unfortunately, I'm too late for 3.0 release...
The text was updated successfully, but these errors were encountered: