Hi @Collection Team
Thank you for posting your question in the Microsoft Q&A forum.
Please note that our forum is a public platform, and we will modify your image to hide your personal information in the description. Kindly ensure that you hide any personal or organizational information the next time you post an error or other details to protect personal data.
You’re running into a browser security change, not an OAuth issue. When Microsoft login pages send the header Cross-Origin-Opener-Policy: same-origin; report-to="coop-endpoint", modern browsers place that page in a separate browsing context group. As a result, window.opener is intentionally set to null for cross-origin popups, so calls like window.opener.postMessage(...) stop working after the redirect from login.windows.net or login.microsoftonline.com.
This behavior is enforced by the browser as part of the Cross-Origin-Opener-Policy (COOP) specification and cannot be overridden by your application.
Here are some options you may consider:
1.Use redirect flow instead of popup
-Redirect the main window with window.location.href = authorizeUrl .
-User signs in on Microsoft’s domain.
-Microsoft redirects back to your redirect URI.
-Your app reads the authorization code from the query string.
-Exchange the authorization code for tokens.
-This avoids window.opener entirely.
2.Use redirect + postMessage from your own redirect page.
If you must keep a popup-based experience:
-Set your redirect URI to a page you control, e.g. https://yourapp.com/auth-callback.html.
-After Microsoft completes authentication, it redirects the popup to that page.
-Since the page is now on your domain, it can safely execute:
window.opener.postMessage(authData, "https://yourapp.com");
window.close();
Important notes:
-The postMessage must originate from your domain, not from Microsoft’s login domain.
-The redirect page must not send a restrictive COOP header (such as Cross-Origin-Opener-Policy: same-origin), otherwise window.opener will remain unavailable.
-The popup must not be opened with noopener, as that also nullifies window.opener.
-The redirect page must be same-origin with the parent window.
Once the popup navigates away from Microsoft’s isolated page and loads your same-origin redirect page (without COOP isolation), the opener relationship can be available again, allowing postMessage to succeed.
I hope this helps clarify the behavior and available options.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.