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

Added OIDC flow to SmartTrader #855

Closed
wants to merge 125 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
a0eec60
feat: added poc for oidc login
adrienne-deriv Oct 14, 2024
8a8d1a1
chore: use auth-client for requesting auth and oidc configuration
adrienne-deriv Oct 15, 2024
36536ed
chore: make eslint happy
adrienne-deriv Oct 15, 2024
ccfdf95
chore: make eslint happy
adrienne-deriv Oct 15, 2024
bb043fc
Merge branch 'poc-oidc' of github.com:adrienne-deriv/smarttrader into…
adrienne-deriv Oct 15, 2024
1b6e6ae
Merge branch 'master' of github.com:adrienne-deriv/smarttrader into p…
adrienne-deriv Nov 6, 2024
812acb1
chore: backup
adrienne-deriv Nov 11, 2024
665255c
chore: backup
adrienne-deriv Nov 15, 2024
c57129b
Merge branch 'master' of github.com:deriv-com/smarttrader into poc-oi…
adrienne-deriv Nov 15, 2024
68a998d
chore: ermoved unecessary changes
adrienne-deriv Nov 15, 2024
aed9fbc
chore: removed development changes
adrienne-deriv Nov 15, 2024
b0bbb43
chore: integrate with latest version of auth-client
adrienne-deriv Nov 19, 2024
7251a42
adrienne-deriv Nov 19, 2024
71ff52a
chore: reverted changes to analytics version
adrienne-deriv Nov 19, 2024
53a5366
chore: reverted changes to analytics version
adrienne-deriv Nov 19, 2024
a0b9293
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 19, 2024
10add16
chore: updated package-lock
adrienne-deriv Nov 19, 2024
28a26f0
chore: disable eslint for testing poc
adrienne-deriv Nov 19, 2024
f3bd46a
chore: disable eslint for testing poc
adrienne-deriv Nov 19, 2024
8c96ef4
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 19, 2024
be2aa24
adrienne-deriv Nov 19, 2024
3116340
chore: edit redirect
adrienne-deriv Nov 19, 2024
12a926d
feat: removed deriv-iframe
adrienne-deriv Nov 25, 2024
4107c8b
chore: make eslint happy
adrienne-deriv Nov 25, 2024
1f91446
chore: removed html format from redirect uri
adrienne-deriv Nov 25, 2024
b9074a9
chore: fix style undefined
adrienne-deriv Nov 25, 2024
87eb912
chore: fix style undefined
adrienne-deriv Nov 25, 2024
50da890
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 25, 2024
cfe71b6
chore: updated auth-client
adrienne-deriv Nov 25, 2024
501cdb7
chore: updated auth-client
adrienne-deriv Nov 25, 2024
ca32a53
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 25, 2024
f9cf0b8
chore: regenerate pacakge-lock
adrienne-deriv Nov 25, 2024
420717d
chore: test build
adrienne-deriv Nov 25, 2024
53035fa
chore: revert auth-client to version before it installed testing library
adrienne-deriv Nov 25, 2024
74f78df
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 25, 2024
26b35d5
feat: added checks for cookies for silent login
adrienne-deriv Nov 25, 2024
de1e28e
chore: make eslint happy
adrienne-deriv Nov 25, 2024
bbe9ca9
feat: added sso logic with cookie checks
adrienne-deriv Nov 26, 2024
d76eb41
feat: added sso logic with cookie checks
adrienne-deriv Nov 26, 2024
0f93afe
chore: debug sso
adrienne-deriv Nov 26, 2024
f7aeed2
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 26, 2024
30bd381
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 26, 2024
52f2aef
chore: debug oidc
adrienne-deriv Nov 26, 2024
9ab86b2
chore: debug oidc
adrienne-deriv Nov 26, 2024
33aeb3f
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 26, 2024
fc8a882
adrienne-deriv Nov 26, 2024
1ad7336
chore: console log for debug
adrienne-deriv Nov 26, 2024
6a9cb64
chore: debug
adrienne-deriv Nov 26, 2024
0043649
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 26, 2024
84f488e
chore: make eslint happy
adrienne-deriv Nov 26, 2024
27141ed
chore: removed timeout for logout
adrienne-deriv Nov 26, 2024
24ce47c
chore: removed timeout for logout
adrienne-deriv Nov 26, 2024
c9953f3
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 26, 2024
4ad6f8a
chore: added logs for testing
adrienne-deriv Nov 26, 2024
962e7b9
chore: added check for endpoint page for silent login
adrienne-deriv Nov 26, 2024
7dee45c
chore: test cookie set
adrienne-deriv Nov 27, 2024
e4bc5ed
chore: test cookie set
adrienne-deriv Nov 27, 2024
2584b8c
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
1f26231
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
ae77db2
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
a641869
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
b405ad0
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
84710f5
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
4a14e25
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
338efba
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
3654995
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
901370a
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
febd81c
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
c83e354
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
f7b7bb2
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
17441a6
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
fc6494b
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
fd1d560
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
9f6124e
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
940b97e
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
ffee2e2
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
227e38a
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
5d744ae
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
9649585
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
2f376b5
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
8bf5dfa
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
3a7900d
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
799fe7f
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
93cfe40
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 27, 2024
5fb7037
chore: make eslint happy
adrienne-deriv Nov 27, 2024
7980d38
chore: make eslint very happy, added config too
adrienne-deriv Nov 27, 2024
46228db
chore: added comments and test remove webpack alias
adrienne-deriv Nov 27, 2024
ad43311
chore: try a different package-lock
adrienne-deriv Nov 29, 2024
eeffaa5
chore: try a different package-lock
adrienne-deriv Nov 29, 2024
bb3ed14
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
6949d0c
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
b0d5b8b
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
2bc42aa
chore: added browserlist for fixing build issues with eslint
adrienne-deriv Nov 29, 2024
d65f341
chore: added browserlist for fixing build issues with eslint
adrienne-deriv Nov 29, 2024
2f0e547
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
95694b8
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
be4bb06
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
586ef75
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
fb379d4
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
2b6dd40
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
08a9893
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
a525b54
chore: revert all changes from babelrc
adrienne-deriv Nov 29, 2024
0b445ef
chore: revert all changes from babelrc
adrienne-deriv Nov 29, 2024
3b130ee
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
8c9a2d1
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
672b89c
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
c055390
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
e6be927
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
5d03ecc
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
fa28625
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
2a4d8e3
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
cf2ba37
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
ab44a94
chore: still fixing the eslint issue :(
adrienne-deriv Nov 29, 2024
d4ade52
chore: still fixing the eslint issue :(
adrienne-deriv Nov 29, 2024
e532eae
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
1ddf226
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Nov 29, 2024
4c59510
Merge branch 'oidc-flow' of github.com:adrienne-deriv/smarttrader int…
adrienne-deriv Dec 2, 2024
e869d2d
adrienne-deriv Dec 2, 2024
1ce509e
chore: eslint broke again
adrienne-deriv Dec 2, 2024
cd06998
chore: idk
adrienne-deriv Dec 2, 2024
160d436
chore: idk
adrienne-deriv Dec 2, 2024
a7c4196
chore: fu
adrienne-deriv Dec 2, 2024
defe378
chore: try to upgrade cookie-js
adrienne-deriv Dec 2, 2024
7865236
chore: passing package.json, debug logout state
adrienne-deriv Dec 2, 2024
29f9de4
chore: regenerate package-lock
adrienne-deriv Dec 2, 2024
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
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
}
]
]
}
}
17 changes: 17 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"singleQuote": true,
"tabWidth": 4,
"semi": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"arrowParens": "avoid",
"printWidth": 100,
"endOfLine": "lf",
"object-property-newline": "always",
"key-spacing": {
"beforeColon": false,
"afterColon": true,
"mode": "strict"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added prettier config to enable autofix in Vscode

}
12,386 changes: 6,988 additions & 5,398 deletions package-lock.json

Large diffs are not rendered by default.

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.0.15",
"@deriv-com/auth-client": "1.2.15",
"@deriv-com/quill-ui": "^1.16.2",
"@deriv-com/utils": "^0.0.38",
"@deriv/deriv-api": "^1.0.15",
Expand Down
1 change: 1 addition & 0 deletions scripts/config/pages.js

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

83 changes: 72 additions & 11 deletions src/javascript/_common/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
URLConstants,
WebSocketUtils,
} = require('@deriv-com/utils');
const Cookies = require('js-cookie');
const requestOidcAuthentication = require('@deriv-com/auth-client').requestOidcAuthentication;
const Analytics = require('./analytics');

export const DEFAULT_OAUTH_LOGOUT_URL = 'https://oauth.deriv.com/oauth2/sessions/logout';
Expand Down Expand Up @@ -79,22 +81,33 @@

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

if (!isAuthEnabled) {
return onWSLogoutAndRedirect;
}

const onMessage = async event => {
const allowedOrigin = getOAuthOrigin();
if (allowedOrigin === event.origin) {
if (event.data === 'logout_complete') {
try {
await onWSLogoutAndRedirect();
} catch (err) {
// eslint-disable-next-line no-console
console.error(`logout was completed successfully on oauth hydra server, but logout handler returned error: ${err}`);
}
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();
}
};

Expand All @@ -113,8 +126,10 @@
iframe.style.display = 'none';
document.body.appendChild(iframe);

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

Expand All @@ -123,3 +138,49 @@

return oAuth2Logout;
};

export const requestSingleSignOn = async () => {
const _requestSingleSignOn = async () => {

Check warning on line 143 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected dangling '_' in '_requestSingleSignOn'

Check warning on line 143 in src/javascript/_common/auth.js

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected dangling '_' in '_requestSingleSignOn'
// if we have previously logged in,
// this cookie will be set by the Callback page (which is exported from @deriv-com/auth-client library) to true when we have successfully logged in from other apps
const isLoggedInCookie = Cookies.get('logged_state') === 'true';
const clientAccounts = JSON.parse(localStorage.getItem('client.accounts') || '{}');
const isClientAccountsPopulated = Object.keys(clientAccounts).length > 0;
const isAuthEnabled = isOAuth2Enabled();
const isCallbackPage = window.location.pathname.includes('callback');
const isEndpointPage = window.location.pathname.includes('endpoint');

// we only do SSO if:
// we have previously logged-in before from SmartTrader or any other apps (Deriv.app, etc) - isLoggedInCookie
// if we are not in the callback route to prevent re-calling this function - !isCallbackPage
// if client.accounts in localStorage is empty - !isClientAccountsPopulated
// and if feature flag for OIDC Phase 2 is enabled - isAuthEnabled
if (isLoggedInCookie && !isCallbackPage && !isEndpointPage && !isClientAccountsPopulated && isAuthEnabled) {
await requestOidcAuthentication({
redirectCallbackUri: `${window.location.origin}/en/callback`,
});
}
};

const isGrowthbookLoaded = Analytics.isGrowthbookLoaded();
if (!isGrowthbookLoaded) {
let retryInterval = 0;
// this interval is to check if Growthbook is already initialised.
// If not, keep checking it (max 10 times) and SSO if conditions are met
const interval = setInterval(() => {
if (retryInterval > 10) {
clearInterval(interval);
} else {
const isLoaded = Analytics.isGrowthbookLoaded();
if (isLoaded) {
_requestSingleSignOn();
clearInterval(interval);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interval is to check if Growthbook has already been loaded. If not, wait for it to be initialised and attempt to SSO if conditions are met

} else {
retryInterval += 1;
}
}
}, 500);
} else {
_requestSingleSignOn();
}
};
2 changes: 2 additions & 0 deletions src/javascript/app/base/binary_pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// ==================== app ====================
const LoggedInHandler = require('./logged_in');
const CallbackHandler = require('./callback');
// const Redirect = require('./redirect');
// const AccountTransfer = require('../pages/cashier/account_transfer');
// const Cashier = require('../pages/cashier/cashier');
Expand Down Expand Up @@ -98,6 +99,7 @@ const pages_config = {
// landing_page : { module: StaticPages.LandingPage, is_authenticated: true, only_virtual: true },
// limitsws : { module: Limits, is_authenticated: true, no_mf: true, only_real: true, needs_currency: true },
logged_inws: { module: LoggedInHandler },
callback : { module: CallbackHandler },
// lost_passwordws : { module: LostPassword, not_authenticated: true },
// malta : { module: StaticPages.Locations },
// maltainvestws : { module: FinancialAccOpening, is_authenticated: true },
Expand Down
16 changes: 16 additions & 0 deletions src/javascript/app/base/callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const SocketCache = require('../../_common/base/socket_cache');
const CallbackElement = require('../pages/callback/callback.jsx');

const CallbackHandler = (() => {
const onLoad = async () => {
parent.window.is_logging_in = 1; // this flag is used in base.js to prevent auto-reloading this page
CallbackElement.init();
SocketCache.clear();
};

return {
onLoad,
};
})();

module.exports = CallbackHandler;
92 changes: 54 additions & 38 deletions src/javascript/app/base/header.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
// const BinaryPjax = require('./binary_pjax');
const Client = require('./client');
const BinarySocket = require('./socket');
const AuthClient = require('../../_common/auth');
const showHidePulser = require('../common/account_opening').showHidePulser;
const updateTotal = require('../pages/user/update_total');
const isAuthenticationAllowed = require('../../_common/base/client_base').isAuthenticationAllowed;
const GTM = require('../../_common/base/gtm');
const Login = require('../../_common/base/login');
const SocketCache = require('../../_common/base/socket_cache');
const requestOidcAuthentication = require('@deriv-com/auth-client').requestOidcAuthentication;
const Client = require('./client');
const BinarySocket = require('./socket');
const AuthClient = require('../../_common/auth');
const showHidePulser = require('../common/account_opening').showHidePulser;
const updateTotal = require('../pages/user/update_total');
const isAuthenticationAllowed = require('../../_common/base/client_base').isAuthenticationAllowed;
const GTM = require('../../_common/base/gtm');
const Login = require('../../_common/base/login');
const SocketCache = require('../../_common/base/socket_cache');
// const elementInnerHtml = require('../../_common/common_functions').elementInnerHtml;
const getElementById = require('../../_common/common_functions').getElementById;
const localize = require('../../_common/localize').localize;
const localizeKeepPlaceholders = require('../../_common/localize').localizeKeepPlaceholders;
const State = require('../../_common/storage').State;
const Url = require('../../_common/url');
const applyToAllElements = require('../../_common/utility').applyToAllElements;
const createElement = require('../../_common/utility').createElement;
const findParent = require('../../_common/utility').findParent;
const getTopLevelDomain = require('../../_common/utility').getTopLevelDomain;
const getPlatformSettings = require('../../../templates/_common/brand.config').getPlatformSettings;
const getHostname = require('../../_common/utility').getHostname;
const template = require('../../_common/utility').template;
const Language = require('../../_common/language');
const mapCurrencyName = require('../../_common/base/currency_base').mapCurrencyName;
const isEuCountry = require('../common/country_base').isEuCountry;
const DerivIFrame = require('../pages/deriv_iframe.jsx');
const DerivLiveChat = require('../pages/livechat.jsx');
const openChat = require('../../_common/utility.js').openChat;
const getRemoteConfig = require('../hooks/useRemoteConfig').getRemoteConfig;
const getElementById = require('../../_common/common_functions').getElementById;
const localize = require('../../_common/localize').localize;
const localizeKeepPlaceholders = require('../../_common/localize').localizeKeepPlaceholders;
const State = require('../../_common/storage').State;
const Url = require('../../_common/url');
const applyToAllElements = require('../../_common/utility').applyToAllElements;
const createElement = require('../../_common/utility').createElement;
const findParent = require('../../_common/utility').findParent;
const getTopLevelDomain = require('../../_common/utility').getTopLevelDomain;
const getPlatformSettings = require('../../../templates/_common/brand.config').getPlatformSettings;
const getHostname = require('../../_common/utility').getHostname;
const template = require('../../_common/utility').template;
const Language = require('../../_common/language');
const mapCurrencyName = require('../../_common/base/currency_base').mapCurrencyName;
const isEuCountry = require('../common/country_base').isEuCountry;
const DerivLiveChat = require('../pages/livechat.jsx');
const openChat = require('../../_common/utility.js').openChat;
const getRemoteConfig = require('../hooks/useRemoteConfig').getRemoteConfig;

const header_icon_base_path = '/images/pages/header/';
const wallet_header_icon_base_path = '/images/pages/header/wallets/';
Expand All @@ -45,7 +45,6 @@ const Header = (() => {
};

const onLoad = () => {
DerivIFrame.init();
populateAccountsList();
populateWalletAccounts();
bindSvg();
Expand Down Expand Up @@ -650,11 +649,25 @@ const Header = (() => {
// }
// };

const loginOnClick = (e) => {
const loginOnClick = async (e) => {
e.preventDefault();
Login.redirectToLogin();
const isOAuth2Enabled = AuthClient.isOAuth2Enabled();

if (isOAuth2Enabled) {
const redirectCallbackUri = `${window.location.origin}/en/callback`;
const postLoginRedirectUri = window.location.href;
const postLogoutRedirectUri = `${window.location.origin}/en/trading`;
// Test commit
await requestOidcAuthentication({
redirectCallbackUri,
postLoginRedirectUri,
postLogoutRedirectUri,
});
} else {
Login.redirectToLogin();
}
};

const logoutOnClick = async () => {
window.fcWidget?.user.clear().then(
() => window.fcWidget.destroy(),
Expand All @@ -663,8 +676,10 @@ const Header = (() => {
// This will wrap the logout call Client.sendLogoutRequest with our own logout iframe, which is to inform Hydra that the user is logging out
// and the session should be cleared on Hydra's side. Once this is done, it will call the passed-in logout handler Client.sendLogoutRequest.
// If Hydra authentication is not enabled, the logout handler Client.sendLogoutRequest will just be called instead.
const onLogoutWithOauth = await AuthClient.getLogoutHandler(Client.sendLogoutRequest);

const onLogoutWithOauth = await AuthClient.getLogoutHandler(
Client.sendLogoutRequest
);

onLogoutWithOauth();
};

Expand Down Expand Up @@ -891,13 +906,14 @@ const Header = (() => {
const account_switcher_seperator = document.getElementById('cfd-link-seperator');
const multiplier_text = localize('Multipliers');
const account_header = document.querySelectorAll('.header__accounts-multiple');
const is_callback_page = window.location.pathname.includes('callback');
let is_virtual;
if (current_active_login) {
is_virtual = current_active_login.startsWith('VRTC');
}
const showTradersHubLink = (show) => {
traders_hub_link.style.display = show ? 'flex' : 'none';
account_switcher_seperator.style.display = show ? 'block' : 'none';
if (traders_hub_link.style) traders_hub_link.style.display = show ? 'flex' : 'none';
if (account_switcher_seperator.style) account_switcher_seperator.style.display = show ? 'block' : 'none';
};

account_header.forEach(header => {
Expand All @@ -908,8 +924,8 @@ const Header = (() => {
$(`<span class="header__acc-display-text">${multiplier_text}</span>`).insertAfter('#header__acc-balance');
}

if (has_real_account) showTradersHubLink(true);
if (is_virtual) showTradersHubLink(true);
if (has_real_account && !is_callback_page) showTradersHubLink(true);
if (is_virtual && !is_callback_page) showTradersHubLink(true);
if (is_virtual || !has_real_account) {
manage_acc_btn.style.visibility = 'hidden';
}
Expand Down
2 changes: 0 additions & 2 deletions src/javascript/app/base/logged_in.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ const removeCookies = require('../../_common/storage').removeCookies;
const paramsHash = require('../../_common/url').paramsHash;
const urlFor = require('../../_common/url').urlFor;
const getPropertyValue = require('../../_common/utility').getPropertyValue;
const DerivIFrame = require('../pages/deriv_iframe.jsx');

const LoggedInHandler = (() => {
const onLoad = () => {
SocketCache.clear();
parent.window.is_logging_in = 1; // this flag is used in base.js to prevent auto-reloading this page
let redirect_url;
const params = paramsHash(window.location.href);
DerivIFrame.init();
BinarySocket.send({ authorize: params.token1 }).then((response) => {
const account_list = getPropertyValue(response, ['authorize', 'account_list']);
if (isStorageSupported(localStorage) && isStorageSupported(sessionStorage) && account_list) {
Expand Down
2 changes: 2 additions & 0 deletions src/javascript/app/base/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const toISOFormat = require('../../_common/string_util').toISOFormat;
const Url = require('../../_common/url');
const Analytics = require('../../_common/analytics');
const { openChatWithParam } = require('../../_common/utility');
const { requestSingleSignOn } = require('../../_common/auth');
const createElement = require('../../_common/utility').createElement;
const isLoginPages = require('../../_common/utility').isLoginPages;
const isProduction = require('../../config').isProduction;
Expand Down Expand Up @@ -100,6 +101,7 @@ const Page = (() => {
updateLinksURL('#content');
} else {
init();
requestSingleSignOn();
if (!isLoginPages()) {
Language.setCookie(Language.urlLang());
const url_query_strings = Url.paramsHash();
Expand Down
Loading
Loading