Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [CXX-15322] Add option to send account id #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export class Instance extends React.PureComponent {
instanceState: undefined,
configWizardSrc: undefined,
authExternalId: undefined,
authUrlParams: ''
authUrlParams: '',
accountId: ''
};

openWizard = (openInIframe, addCustomValidation = false) => {
Expand Down Expand Up @@ -78,7 +79,7 @@ export class Instance extends React.PureComponent {
onCreateAuth = () => {
getAuthCreateUrl(this.props.id, this.state.authExternalId)
.then(({body}) => {
openAuthWindow(`${body.data.popupUrl}&${this.state.authUrlParams}`);
openAuthWindow(`${body.data.popupUrl}&${this.state.authUrlParams}`, this.state.accountId);
})
};

Expand Down Expand Up @@ -202,6 +203,15 @@ export class Instance extends React.PureComponent {
shrink: true,
}}
/>
<TextField
style={styles.textFields}
label="Account id (For use with enhanced session transfer security)"
value={this.state.accountId}
onChange={this.handleChange('accountId')}
InputLabelProps={{
shrink: true,
}}
/>
<Button
style={styles.button}
onClick={this.onCreateAuth}
Expand Down
70 changes: 40 additions & 30 deletions src/lib/authWindow.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,46 @@
export const openAuthWindow = (url) => {
// Must open window from user interaction code otherwise it is likely
// to be blocked by a popup blocker:
const authWindow = window.open(
undefined,
'_blank',
'width=500,height=500,scrollbars=no',
);
export const openAuthWindow = (url, accountId) => {
// Must open window from user interaction code otherwise it is likely
// to be blocked by a popup blocker:
const authWindow = window.open(
undefined,
"_blank",
"width=500,height=500,scrollbars=no"
);

const onmessage = e => {
console.log('message', e.data.type, e.data);
const onmessage = (e) => {

if (e.data.type === 'tray.authPopup.error') {
// Handle popup error message
alert(`Error: ${e.data.error}`);
authWindow.close();
}
if (e.data.type === 'tray.authpopup.close' || e.data.type === 'tray.authpopup.finish') {
authWindow.close();
}
};
window.addEventListener('message', onmessage);
if(e.data.type === "tray.authpopup.accountIdRequest"){
// If the user has the enhancedSessionSecurity option set, they will send a postMessage
// requesting the account ID. Unless the client app responds with the appropriate ID
// the session will not be validated
e.source.postMessage({type: 'tray.authpopup.accountIdRequest', data: accountId},
e.origin);
}

if (e.data.type === "tray.authPopup.error") {
// Handle popup error message
alert(`Error: ${e.data.error}`);
authWindow.close();
}
if (
e.data.type === "tray.authpopup.close" ||
e.data.type === "tray.authpopup.finish"
) {
// authWindow.close();
}
};
window.addEventListener("message", onmessage);

// Check if popup window has been closed
const CHECK_TIMEOUT = 1000;
const checkClosedWindow = () => {
if (authWindow.closed) {
window.removeEventListener('message', onmessage);
} else {
setTimeout(checkClosedWindow, CHECK_TIMEOUT);
}
// Check if popup window has been closed
const CHECK_TIMEOUT = 1000;
const checkClosedWindow = () => {
if (authWindow.closed) {
window.removeEventListener("message", onmessage);
} else {
setTimeout(checkClosedWindow, CHECK_TIMEOUT);
}
};

checkClosedWindow();
authWindow.location = url;
checkClosedWindow();
authWindow.location = url;
};