Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding extra option to msal guard to be stricter, check if active user token is not expired #7161

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

alexgoeman
Copy link

@alexgoeman alexgoeman commented Jun 12, 2024

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

@github-actions github-actions bot added the msal-angular Related to @azure/msal-angular package label Jun 12, 2024
@alexgoeman alexgoeman force-pushed the feature/msal-angular/msal-guard-stricter branch from a3c5053 to 907548e Compare June 12, 2024 09:37
@alexgoeman
Copy link
Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jul 1, 2024
@alexgoeman alexgoeman force-pushed the feature/msal-angular/msal-guard-stricter branch from 907548e to 0a804f5 Compare July 3, 2024 09:56
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jul 3, 2024
@alexgoeman alexgoeman force-pushed the feature/msal-angular/msal-guard-stricter branch from 3adf525 to 8752a84 Compare July 4, 2024 10:40
@github-actions github-actions bot added the documentation Related to documentation. label Jul 4, 2024
@alexgoeman
Copy link
Author

@tnorling
@peterzenz
@jo-arroyo

Would you have any time to have a look at the pull request. I have added tests and documentation.
If any question please let me know.
Thx

Copy link
Contributor

Reminder: This PR appears to be stale. If this PR is still a work in progress please mark as draft.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Related to documentation. msal-angular Related to @azure/msal-angular package Needs: Attention 👋 Awaiting response from the MSAL.js team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant