Skip to content

Commit

Permalink
Merge branch 'master' into Hirad/TRAH-4591/redirecting-outsystems-to-…
Browse files Browse the repository at this point in the history
…legacy-and-log-user-in
  • Loading branch information
hirad-deriv authored Dec 9, 2024
2 parents 2b0727f + 8a982fb commit 1a5db75
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 73 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"@binary-com/binary-style": "^0.2.26",
"@binary-com/webtrader-charts": "^0.6.2",
"@deriv-com/analytics": "^1.26.1",
"@deriv-com/auth-client": "1.3.1",
"@deriv-com/auth-client": "1.3.3",
"@deriv-com/quill-ui": "^1.16.2",
"@deriv-com/utils": "^0.0.38",
"@deriv/deriv-api": "^1.0.15",
Expand Down
60 changes: 2 additions & 58 deletions src/javascript/_common/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ const {
} = require('@deriv-com/utils');
const Cookies = require('js-cookie');
const requestOidcAuthentication = require('@deriv-com/auth-client').requestOidcAuthentication;
const handlePostLogout = require('@deriv-com/analytics').handlePostLogout;
const Analytics = require('./analytics');

export const DEFAULT_OAUTH_LOGOUT_URL = 'https://oauth.deriv.com/oauth2/sessions/logout';

export const DEFAULT_OAUTH_ORIGIN_URL = 'https://oauth.deriv.com';

const LOGOUT_HANDLER_TIMEOUT = 10000;

const SocketURL = {
[URLConstants.derivP2pProduction]: 'blue.derivws.com',
[URLConstants.derivP2pStaging] : 'red.derivws.com',
Expand Down Expand Up @@ -80,62 +79,7 @@ export const isOAuth2Enabled = () => {
};

export const getLogoutHandler = onWSLogoutAndRedirect => {
const isAuthEnabled = isOAuth2Enabled();
let timeout;

if (!isAuthEnabled) {
return onWSLogoutAndRedirect;
}

const cleanup = () => {
clearTimeout(timeout);

const iframe = document.getElementById('logout-iframe');
if (iframe) iframe.remove();
};

const onMessage = event => {
if (event.data === 'logout_complete') {
const domains = ['deriv.com', 'binary.sx', 'pages.dev', 'localhost'];
const currentDomain = window.location.hostname.split('.').slice(-2).join('.');
if (domains.includes(currentDomain)) {
Cookies.set('logged_state', 'false', {
expires: 30,
path : '/',
secure : true,
});
}
onWSLogoutAndRedirect();
window.removeEventListener('message', onMessage);
cleanup();
}
};

window.addEventListener('message', onMessage);

const oAuth2Logout = () => {
if (!isAuthEnabled) {
onWSLogoutAndRedirect();
return;
}

let iframe = document.getElementById('logout-iframe');
if (!iframe) {
iframe = document.createElement('iframe');
iframe.id = 'logout-iframe';
iframe.style.display = 'none';
document.body.appendChild(iframe);

timeout = setTimeout(() => {
onWSLogoutAndRedirect();
window.removeEventListener('message', onMessage);
cleanup();
}, LOGOUT_HANDLER_TIMEOUT);
}

iframe.src = getOAuthLogoutUrl();
};

const oAuth2Logout = handlePostLogout(onWSLogoutAndRedirect);
return oAuth2Logout;
};

Expand Down
10 changes: 0 additions & 10 deletions src/javascript/app/pages/callback/callback.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,6 @@ const CallbackContainer = () => {
}
getElementById('loading_link').setAttribute('href', redirect_url);

const domains = ['deriv.com', 'binary.sx', 'pages.dev', 'localhost'];
const currentDomain = window.location.hostname.split('.').slice(-2).join('.');
if (domains.includes(currentDomain)) {
Cookies.set('logged_state', 'true', {
expires: 30,
path : '/',
secure : true,
});
}

window.location.href = redirect_url; // need to redirect not using pjax
});
};
Expand Down

0 comments on commit 1a5db75

Please sign in to comment.