Today, I was tasked to do the authentication in SSO and for this we have APIs created to handle the authentication part, from UI we had to manage the logic. One thing where we had to open the SSO screen that can’t be open in iframe, so we had to open it in new window and once complete then we had to post the message back to the message listener. So, message event is the event in DOM which will listen to the messages that are posted. And the messages are posted using Window.postMessage() method and the message will land in the handler.
window.addEventListener(‘message’, (event) => {}); and then use Window.postMessage(message);
Summary
- Message event is used to listen messages that are posted by the client publisher.
- You have to register the message event and the handler that will handler the call back request.
- Post the message using Window.postMessage() method.
0 Comments