
Hello Kanika Chawla.
Thank you for reaching out. I’m sincerely sorry if this issue causes you any inconvenience.
I can see you’ve already received an accepted answer on our Q&A forum at Getting error when trying to get user access token in SPfx solution using MSAL - Microsoft Q&A . Although this issue is beyond our support level, I still took time to research and provide you with some more suggestions you may want to try:
1. Use SPFx's Built-In Token Acquisition:
AadHttpClient and MSGraphClient are designed to handle token acquisition seamlessly within the SPFx environment. These classes manage the authentication flow and token caching, reducing the complexity of handling tokens manually.
Reference: Connect to Azure AD-secured APIs in SharePoint Framework solutions | Microsoft Learn
2. Check for Third-Party Cookie and Single Sign-On Issues:
Enable Third-Party Cookies:
- If you’re using Microsoft Edge: Go to Settings > Cookies and site permissions > Manage and delete cookies and site data. Ensure "Block third-party cookies" is turned off.
Check Single Sign-On (SSO) Configuration:
- Ensure that your SharePoint environment is correctly configured for SSO. This includes verifying that the necessary permissions and admin consents are granted.
- Use the special single sign-on page (/_forms/spfxsinglesignon.aspx) to handle SSO cases. This page helps manage authentication flows and can resolve issues related to third-party cookies.
3. Upgrade to MSAL.js v2 (MSAL Browser):
MSAL.js v2 uses the Authorization Code Flow with PKCE, which enhances security and improves token refresh handling.
This version reduces the need for redirects after the initial sign-in, which can help avoid iframe navigation issues.
Feel free to reply if you need any further assistance. Thank you for your patience and cooperation!
Best regards,
Tamara-Hu - MSFT | Microsoft Community Support Specialist.