From 71e9b1fc2755efeecd953182aca44db82a5cbdd8 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Fri, 21 Dec 2018 10:44:35 -0300 Subject: [PATCH] Add the onMessage handler when sso completes (#2474) * Add the onMessage handler when sso completes * Enable handler only for mattermost server --- app/screens/sso/sso.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/screens/sso/sso.js b/app/screens/sso/sso.js index bd32b5cf0..ac6b4d914 100644 --- a/app/screens/sso/sso.js +++ b/app/screens/sso/sso.js @@ -79,6 +79,7 @@ class SSO extends PureComponent { error: null, renderWebView: false, jsCode: '', + messagingEnabled: false, }; switch (props.ssoType) { @@ -156,16 +157,20 @@ class SSO extends PureComponent { onNavigationStateChange = (navState) => { const {url} = navState; - const nextState = {}; + const nextState = { + messagingEnabled: false, + }; const parsed = urlParse(url); if (parsed.host.includes('.onelogin.com')) { nextState.jsCode = oneLoginFormScalingJS; + } else if (parsed.pathname === this.completedUrl) { + // To avoid `window.postMessage` conflicts in any of the SSO flows + // we enable the onMessage handler only When the webView navigates to the final SSO URL. + nextState.messagingEnabled = true; } - if (Object.keys(nextState).length) { - this.setState(nextState); - } + this.setState(nextState); }; onLoadEnd = (event) => { @@ -210,7 +215,7 @@ class SSO extends PureComponent { render() { const {theme} = this.props; - const {error, renderWebView, jsCode} = this.state; + const {error, messagingEnabled, renderWebView, jsCode} = this.state; const style = getStyleSheet(theme); let content; @@ -235,14 +240,14 @@ class SSO extends PureComponent { renderLoading={this.renderLoading} injectedJavaScript={jsCode} onLoadEnd={this.onLoadEnd} - onMessage={this.onMessage} + onMessage={messagingEnabled && this.onMessage} useWebKit={true} /> ); } return ( - + {content} @@ -252,6 +257,9 @@ class SSO extends PureComponent { const getStyleSheet = makeStyleSheetFromTheme((theme) => { return { + container: { + flex: 1, + }, errorContainer: { alignItems: 'center', flex: 1,