|
1 | 1 | var urljoin = require('url-join');
|
| 2 | +var WinChan = require('winchan'); |
2 | 3 |
|
3 | 4 | var urlHelper = require('../helper/url');
|
4 | 5 | var assert = require('../helper/assert');
|
@@ -84,17 +85,41 @@ Popup.prototype.getPopupHandler = function(options, preload) {
|
84 | 85 | */
|
85 | 86 | Popup.prototype.callback = function(options) {
|
86 | 87 | var _this = this;
|
| 88 | + var theWindow = windowHelper.getWindow(); |
87 | 89 | options = options || {};
|
88 |
| - var originUrl = |
89 |
| - options.popupOrigin || this.baseOptions.popupOrigin || windowHelper.getWindow().origin; |
90 |
| - _this.webAuth.parseHash(options || {}, function(err, data) { |
91 |
| - // {a, d} is WinChan's message format. |
92 |
| - // We have to keep the same format because we're opening the popup with WinChan. |
93 |
| - var response = { a: 'response', d: data }; |
94 |
| - if (err) { |
95 |
| - response = { a: 'error', d: err }; |
| 90 | + var originUrl = options.popupOrigin || this.baseOptions.popupOrigin || windowHelper.getOrigin(); |
| 91 | + |
| 92 | + /* |
| 93 | + in IE 11, there's a bug that makes window.opener return undefined. |
| 94 | + The callback page will still call `popup.callback()` which will run this method |
| 95 | + in the relay page. WinChan expects the relay page to have a global `doPost` function, |
| 96 | + which will be called with the response. |
| 97 | +
|
| 98 | + IE11 Bug: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/110920/ |
| 99 | + */ |
| 100 | + if (!theWindow.opener) { |
| 101 | + theWindow.doPost = function(msg) { |
| 102 | + if (theWindow.parent) { |
| 103 | + theWindow.parent.postMessage(msg, originUrl); |
| 104 | + } |
| 105 | + }; |
| 106 | + return; |
| 107 | + } |
| 108 | + |
| 109 | + WinChan.onOpen(function(popupOrigin, r, cb) { |
| 110 | + if (popupOrigin !== originUrl) { |
| 111 | + return cb({ |
| 112 | + error: 'origin_mismatch', |
| 113 | + error_description: "The popup's origin (" + |
| 114 | + popupOrigin + |
| 115 | + ') should match the `popupOrigin` parameter (' + |
| 116 | + originUrl + |
| 117 | + ').' |
| 118 | + }); |
96 | 119 | }
|
97 |
| - windowHelper.getWindow().opener.postMessage(JSON.stringify(response), originUrl); |
| 120 | + _this.webAuth.parseHash(options || {}, function(err, data) { |
| 121 | + return cb(err || data); |
| 122 | + }); |
98 | 123 | });
|
99 | 124 | };
|
100 | 125 |
|
|
0 commit comments