Skip to content

Commit 675cdd1

Browse files
🐛 Update postMessage to call correct origin (#104)
1 parent 71a2172 commit 675cdd1

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/clientBuilder.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ proto.fingerprint = function(options) {
243243
return deferred.resolve(msg.fingerprint);
244244
}
245245
if (msg.type === 'FingerprintServiceReady') {
246-
if (iframe.contentWindow) {
247-
iframe.contentWindow.postMessage(JSON.stringify({
248-
type: 'GetFingerprint'
249-
}), sdk.options.url);
250-
}
246+
e.source.postMessage(JSON.stringify({
247+
type: 'GetFingerprint'
248+
}), e.origin);
251249
}
252250
}
253251
oauthUtil.addListener(window, 'message', listener);

test/spec/fingerprint.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ define(function(require) {
2525

2626
test.iframe = {
2727
style: {},
28-
contentWindow: {
29-
postMessage: postMessageSpy
30-
},
3128
parentElement: {
3229
removeChild: jasmine.createSpy('removeChild')
3330
}
@@ -55,7 +52,10 @@ define(function(require) {
5552
data: options.firstMessage || JSON.stringify({
5653
type: 'FingerprintServiceReady'
5754
}),
58-
origin: 'http://example.okta.com'
55+
origin: 'http://example.okta.com',
56+
source: {
57+
postMessage: postMessageSpy
58+
}
5959
});
6060
});
6161
});
@@ -80,6 +80,7 @@ define(function(require) {
8080
expect(test.iframe.style.display).toEqual('none');
8181
expect(test.iframe.src).toEqual('http://example.okta.com/auth/services/devicefingerprint');
8282
expect(document.body.appendChild).toHaveBeenCalledWith(test.iframe);
83+
expect(test.e.source.postMessage).toHaveBeenCalled();
8384
expect(test.iframe.parentElement.removeChild).toHaveBeenCalled();
8485
expect(fingerprint).toEqual('ABCD');
8586
})

0 commit comments

Comments
 (0)