Comments (6)
Hey just a note this is not fixed if you only pass the msal object back in the callback. The iframe generated to acquire a token silently will fail because it relies on the parent Windows msal object, and if you have multiple instances the token acquiring will not work because it tries to verify that the response matches your msal ID. This took forever to debut and fix; I can post a summary sometime soon to show which code points cause issues.
The long and short of it is that the msal object being tied to the window causes problems that we have to dance around.
from microsoft-authentication-library-for-js.
Thanks @Wozbo. I believe this makes sense. We'll consider it for the backlog
from microsoft-authentication-library-for-js.
@Wozbo Can you try out my branch https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/rohitnarula7176/Issue_82 and let me know if it fixes the issue. With this change you can use 'this' inside the tokenRecievedCallback function to refer to the instance of the userAgentApplication as shown below:
var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientID, null, authCallback);
function authCallback(errorDesc, token, error, tokenType) {
//This function is called after loginRedirect. Inside the function, this will refer to the userAgentApplication instance.
if (token) {
this.acquireTokenSilent(applicationConfig.graphScopes).then(function (accessToken) {
// Change button to Sign Out
updateUI();
}, function (error) {
console.log(error);
this.acquireTokenPopup(applicationConfig.graphScopes).then(function (accessToken) {
updateUI();
}, function (error) {
console.log(error);
});
});
}
else if (errorDesc || error) {
console.log(error + ':' + errorDesc);
}
}
from microsoft-authentication-library-for-js.
Hey, this looks pretty good! With this, is there any need for the window.msal object? Seems like a potential artifact that could be removed to not cause confusion.
from microsoft-authentication-library-for-js.
Hey, I spoke too soon; this fails in an angular service because of the usage of 'this.' Is there any other solution that would be better and backward compatible?
from microsoft-authentication-library-for-js.
@Wozbo This is now fixed in dev. I have changed the code in a way that you do not need to rely on the window.msal object in the call back function passed in the constructor. You can just create an instance of userAgentApplication and use that instance in the authCallback. With this fix you can still use this.msal in the callback function as before and also use userAgentApplication instance to support multiple login types making it backwards compatible.
var userAgentApplication = new Msal.UserAgentApplication(applicationConfig.clientID, null, authCallback, { cacheLocation: 'localStorage' });// cacheLocation defaults to sessionStorage if not set in the constructor
function authCallback(errorDesc, token, error, tokenType) {
//This function is called after loginRedirect.
if (token) {
}
else if (errorDesc || error) {
console.log(error + ':' + errorDesc);
}
}
from microsoft-authentication-library-for-js.
Related Issues (20)
- CORS issue with acquireTokenPopup HOT 4
- LoginPopup and LoginRedirect not Working HOT 2
- ManagedIdentityTokenResponse's expires_in is not calculated correctly
- Managed Identity - add logs showing which MSI implementations were tried and why they are not available HOT 1
- Managed Identity - failed network request returns wrong error type
- MSAL 3.0 not returning accounts in Angular 17 after upgrading from 2.16.0 HOT 2
- Angular 17 Standalone MSAL Angular v3 Sample Doesnt work and Documentation is wrong HOT 1
- msal browser sample VanillaJSTestApp2.0 fails with ADFS HOT 2
- MsalContext accounts contains incorrect for authenticated user HOT 1
- The MSAL Interceptor finds invalid resources from the endpoint if another match is found in "QueryString". HOT 2
- sample fails at npm start: Angular 16 MSAL Angular v3 Sample: Cannot find module '@azure/msal-browser' HOT 2
- Error: Uncaught (in promise): InteractionRequiredAuthError: interaction_required: AADB2C90077: User does not have an existing session and request prompt parameter has a value of 'None'. HOT 2
- [Supportability Bug] Deprecate WithClientAssertion(string) as it leads to assertion expiration issues HOT 1
- sample "Angular 16 MSAL Angular v3 Sample" configured for ADFS logs event "msal:loginFailure" HOT 3
- sample "Angular 17 Standalone MSAL Angular v3 Sample" fails to build: Cannot set properties of null (setting 'parent'), Lifecycle script `postinstall:msal-angular` failed, etc.
- Custom state leads to error after upgrading to 3.14.0
- Support for Angular 18 HOT 1
- Issue with Password Reset Redirect Loop in MSAL Browser for B2C Users
- Getting AADB2C90079 after B2C login portal returns to app HOT 1
- Angular SSR support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft-authentication-library-for-js.