Google and Facebook both allow users to "Login with _____". The website developer normally just has to include a Javascript and provide a callback to handle the login response. From my understanding of the JavaScript security in browsers, this should not be possible.
I've read several methods of cross-origin JavaScript communication, such as Porthole or easyXDM. In each of these methods, a small static HTML file is required to be hosted by the developer so that either Facebook or Google (i.e., the 'included' content) can communicate back to the parent frame. An example would be an application (app.example.com) that included an iframe from Google (google.com) which includes an iframe from the application again (app.example.com). The innermost iframe's JavaScript can communicate with the top most window since they are in the same domain (via this.parent.parent
).
+-------------------------------------------------------------+
| https://app.example.com |
+-------------------------------------------------------------+
| |
| +------------(hidden iframe)-----------------------------+ |
| | https://whatever.google.com | |
| +--------------------------------------------------------+ |
| | | |
| | +---------(hidden iframe)--------------------------+ | |
| | | https://app.example.com/receiver | | |
| | +--------------------------------------------------+ | |
| | | | | |
| | | (script that calls this.parent.parent.callback) | | |
| | | | | |
| | +--------------------------------------------------+ | |
| | | |
| +--------------------------------------------------------+ |
| |
+-------------------------------------------------------------+
However, this requires that the innermost iframe contain a 'receiver' page on the app.example.com domain. It's sole purpose is to read it's URL bar and then pass that data up to the parent window. With the Google and Facebook solutions however, no static HTML page is needed. So what mechanism are they using to pass the data back up if not a static receiver page? The JavaScript in their frame should have no access to the parent JavaScript. The Window.PostMessage
seems dubious at best, seeing as it's IE8, IE9, and IE10 implementations are either broken or quirky.