I am currently trying to create a login pop up, sort of like google auth.
I have managed to get everything to work but I have one issue.
Here is how my code works.
- User clicks a login button
- JS code opens pop up to my website with a login page. (The websites can be cross origin so supposedly there can be no communication between the pop up and the opener site.
- Send a POST request to my servers to verify the credentials
I can get these first steps working fine. What I can’t figure out are the next steps
- Once the credentials are verified, the pop up closes
- An embedded JS script somehow sets headers for the entire website with information about the logged in user
How am I supposed to send the POST response back to the script that opened the pop up?
The main problem is that the sites are cross origin, which blocks communication. Thus I am stumped to find a solution.
CodePudding user response:
I found the answer on page 2 of google results.
https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
window.postMessage API allows you to listen for events on parent window by adding an event listener for “message” and grab associated data.