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

Adrienne / Add front channel and silent login to replace logged_state cookies #18069

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

adrienne-deriv
Copy link
Contributor

@adrienne-deriv adrienne-deriv commented Feb 19, 2025

Changes:

Please provide a summary of the change.

  • Add front channels to Deriv.app, which when rendered in an iframe will clear local storage and any related to authentication state
  • Move logged_state syncing logic to only be used in Safari
  • Add silent login feature using prompt=none, which will automatically checks if the user is logged in if client.accounts have not been populated yet, local storage is empty
    • this will render an iframe to /silent-callback.html which will check if user has session in Hydra (which will return a code parameter in the URL)
    • if user does not have a session in Hydra, Hydra will return an query parameter error=login_required which indicates that the user is logged out

Screenshots:

Please provide some screenshots of the change.

Copy link

vercel bot commented Feb 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
deriv-app ✅ Ready (Inspect) Visit Preview Feb 24, 2025 6:36am

Copy link
Contributor

github-actions bot commented Feb 19, 2025

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/deriv-com/deriv-app/pull/18069](https://github.com/deriv-com/deriv-app/pull/18069)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-adrienne-deriv-front-channel-silent-login.binary.sx?qa_server=red.derivws.com&app_id=31898
    - **Original**: https://deriv-app-git-fork-adrienne-deriv-front-channel-silent-login.binary.sx
- **App ID**: `31898`

Copy link
Contributor

github-actions bot commented Feb 19, 2025

Generating Lighthouse report...

@adrienne-deriv adrienne-deriv changed the title Front channel silent login Adrienne / Add front channel and silent login to replace logged_state cookies Feb 20, 2025
// use logged_state cookie login checks for Safari
useLoggedStateLoginAndLogout({
is_client_store_initialized,
isOAuth2Enabled,
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 is to ensure Safari is still using logged_state, because at the moment front channels do not work in Safari due to Storage partitioning in Intelligent Tracking Prevention
Screenshot 2025-02-21 at 4 13 17 PM

https://stackoverflow.com/questions/63921299/safari-setting-localstorage-inside-iframe-is-not-correctly-shared

Copy link
Contributor Author

@adrienne-deriv adrienne-deriv Feb 21, 2025

Choose a reason for hiding this comment

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

So if we log out at https://hub.deriv.com, Hydra will render front channels (i.e. creating iframes in https://hub.deriv.com to https://app.deriv.com/front-channel.html) which SHOULD clear local storage in Chrome and Firefox, but it will not work in Safari due to the issue mentioned above

const isAuthFlow = /\/(silent-callback|front-channel)($|\/)/.test(self.location.pathname);
if (!isAuthFlow) {
top.location = self.location;
}
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 prevents the silent-callback.html and front-channel.html iframes to be navigated in the main window

localStorage.removeItem('verification_code.system_email_change');
localStorage.removeItem('verification_code.request_email');
localStorage.removeItem('new_email.system_email_change');
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we call OIDC logout, it will render all front-channels (including the caller's front channel). This caused an issue in Deriv.app where if you clear the local storage while you are still signing out, after signing out it redirects you to the /authorize page

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 storage clearance is referenced from packages/core/src/Services/logout.js
Screenshot 2025-02-21 at 4 57 16 PM

* }} params - The arguments required for silent login and logout management
*/
const useLoggedStateLoginAndLogout = ({
is_client_store_initialized,
Copy link
Contributor Author

@adrienne-deriv adrienne-deriv Feb 21, 2025

Choose a reason for hiding this comment

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

This is the main hook for the logged_state logic, I just renamed it to useLoggedStateLoginAndLogout from useSilentLoginAndLogout


useEffect(() => {
const isSafariBrowser = isSafari();
if (isSafariBrowser) return;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we are in Safari, don't use prompt none


useEffect(() => {
const isSafariBrowser = isSafari();
if (!isSafariBrowser) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only trigger logged_state checks in Safari

@@ -85,7 +85,10 @@
var antiClickjack = document.getElementById('antiClickjack');
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
const isAuthFlow = /\/(silent-callback|front-channel)($|\/)/.test(self.location.pathname);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] is callback needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested this, this is not needed anymore since the silent callback and front channel are served statically under /silent-callback.html and /front-channel.html, will remove this change

amam-deriv
amam-deriv previously approved these changes Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants