A Microsoft app for iOS and Android devices that enables authentication with two-factor verification, phone sign-in, and code generation
The issue you're experiencing with mixed tokens when using one-time passwords (OTP) for login could be related to how MSAL.js handles session management and token caching. Here are some points to consider:
- Session Management: MSAL.js relies on session cookies set in the browser. If multiple users log in and out in the same browser session, the session state may not be cleared properly, leading to token mixing. This is especially true if the application does not handle logout correctly or if the session is not fully terminated before a new login.
- Token Caching: When using MSAL, tokens are cached in the browser. If the cache is not cleared properly during logout, it may still hold onto the previous user's tokens, which can lead to the issue you're seeing with the
preferred_usernamereflecting the previous user. - Using
ssoSilentMethod: If your application is using thessoSilentmethod for silent token acquisition, ensure that you are passing the correct parameters (likelogin_hintoraccount) to avoid ambiguity when multiple accounts are present in the session. This can help in correctly identifying the user for whom the token is being requested. - Incognito Mode: The fact that the issue does not occur in an incognito window suggests that the problem is related to session persistence in the standard browsing mode. Incognito mode does not retain session cookies or cache between sessions, which is why it works correctly there.
- Logout Implementation: Ensure that your logout implementation is correctly clearing the session and tokens. You may want to explicitly call the logout method provided by MSAL to clear the session state.
- Testing Across Browsers: Since you mentioned multiple browsers, ensure that the behavior is consistent across them. Sometimes, browser-specific caching or session handling can lead to different behaviors.
To resolve this issue, consider implementing a more robust logout process that clears the session and cache, and ensure that you are using the correct parameters when acquiring tokens for different users. You may also want to review the MSAL documentation for best practices on managing sessions and tokens effectively.
References: