Closed Taerarenai closed 6 years ago
Checking the user solved it.
// Check For & Handle Redirect From AAD After Login
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
console.log(authContext.getLoginError());
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
// Check Login Status, Update UI
var user = authContext.getCachedUser();
if (user) {
console.log("User found");
} else {
console.log("error");
authContext.config.redirectUri = window.location.href;
authContext.login();
}
The title pretty much sums it up. Im using adal token to access a specific api. It all works as it should, unless i edit the JS (i added Loading Overlay so it shows a loading icon until the api call is Done). After that, i just get ->
Im guessing its unauthorized because the token is wrong (cached token is exactly the same, but im still new to this so thats how it should be perhaps?).
My only fix so far is to purposely break the script (token) by calling the wrong appid here ->
authContext.acquireToken(authContext.config.clientId, function (error, token) {
By calling clientId (instead of the id of the app that we need to auth against) it gets into a refresh loop (trying to login i suppose) and thus removes the token. After that i can just repair the script with the correct id and it works.Isnt there another way to remove the unwanted token and refresh? (afaik adal should refresh, but does that work if the token is not the one the app is after or just if theres no token/expired?)
I'm asking this because it would be rather impossible to fix all users problems by doing what im doing locally, therefore i need a way to remove the token if its not working and get a new one.
Adal token is set with cacheLocation: 'localStorage' (from what ive read it is needed for IE and we still have people using IE).
I'm using adaljs 1.0.17 I hope i didnt confuse you too much. Thanks in advance.