Trying to get access token for currently logged user in SPFx solution using MSAL

Anonymous
2025-07-07T07:43:18+00:00

Trying to get access token for currently logged user in SPFx solution using MSAL

Error: Unsafe attempt to initiate navigation for frame with origin 'https://XXXX.sharepoint.com' from frame with URL 'https://login.microsoftonline.com/XXXXXXXX-595d-472c-8248-0dc58f852d61/oaut…04MDZhLTc4NTFlOGEzNWJjNSIsIm1ldGEiOnsiaW50ZXJhY3Rpb25UeXBlIjoic2lsZW50In19'. The frame attempting navigation of the top-level window is sandboxed, but the flag of 'allow-top-navigation' or 'allow-top-navigation-by-user-activation' is not set.

Microsoft 365 and Office | SharePoint | Other | Other

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Anonymous
    2025-07-09T12:16:37+00:00

    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. 

    Reference: Migrate JavaScript single-page app from implicit grant to authorization code flow - Microsoft identity platform | Microsoft Learn 

    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.

    0 comments No comments
  2. Anonymous
    2025-07-11T12:45:02+00:00

    Hi Kanika Chawla, 

    Good day! I hope you're doing well. 

    I just wanted to follow up and see how things are progressing with the issue we discussed. Have you had a chance to review the response provided? Are you experiencing any difficulties performing the providing steps? 

    Please don’t hesitate to reach out if you need any further assistance.

    We value your feedback, please mark it as an Answerif it help resolve your issue/ if it answer your question. This helps others in the community with similar questions find solutions more easily. 

     

    Thank you & Best regards, 

    Tamara-Hu - MSFT | Microsoft Community Support Specialist.

    0 comments No comments
  3. Anonymous
    2025-07-14T13:44:04+00:00

    Hi Tamara-Hu,

    Regarding point 1., As referred we are using sample from Github. So we can't modify the code
    Regarding point 2. and 3., these are already implemented but still we are getting the same issue.

    This error is intermittent and uncertain. Some users face it, some don't.

    Please help!!!

    Thank you

    0 comments No comments
  4. Anonymous
    2025-07-16T08:52:43+00:00

    Hello Kanika Chawla, 

    Thank you for your feedback. 

    To resolve your issue, I recommend you contact Microsoft Technical Support team for further troubleshooting. A technical support engineer can perform a remote session to investigate the situation, verify the backend configurations, and run any necessary synchronization tools to resolve the problem. If the issue requires further attention, they can escalate it to a specialized team for deeper analysis.  I'd love to assist you further, but due to limited resources of a Community Moderator, I cannot perform further troubleshoot steps.
     
    You will need to be a Microsoft 365 admin to raise the support ticket. If you’re not an admin, you can find guidance on locating them at How do I find my Microsoft 365 admin? - Microsoft Support.   

    The Global Admin should create a service request with Microsoft support to get advanced technical assistance and diagnostics. For detailed instructions on how to get support, please refer to Get support - Microsoft 365 admin.       

    Please kindly be noted that Microsoft 365 and Office is now supported on Microsoft Q&A.  Starting July 16, new questions must be posted there. Existing discussions on Microsoft Answers will remain accessible through July 21, after which customers will be redirected to Q&A.

    Feel free to reply if you need any further assistance. Thank you for your kindness and understanding! 

    Best regards, 

    Tamara-Hu - MSFT | Microsoft Community Support Specialist.

    0 comments No comments