adding extra option to msal guard to be stricter, check if active user token is not expired #7161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the MsalGuard will not redirect to login when there is an active user which has an expired token.
So if you use the guard to be sure that no login will be needed going further, then this current implementation of MsalGuard is not enough.
The only check in the guard currently is:
!this.authService.instance.getAllAccounts().length
so only if getAllAccounts().length is falsey it will redirect to login.
But this allows for a account with an expired token.
An extra option is added to MsalGuardConfiguration:
enableCheckForExpiredToken?: boolean;
So if enableCheckForExpiredToken is false or does not exist then behavior is as before.
When enableCheckForExpiredToken true then we do a check if the token is not expired on the
"this.authService.instance.getActiveAccount()". If expired or no active user a login will be done
Extra option is included so that when token is expired, a silentRefresh is attempted and if succesfull then route activation can continue