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 / Integrate Hydra authentication #821

Merged

Conversation

adrienne-deriv
Copy link
Contributor

@adrienne-deriv adrienne-deriv commented Sep 24, 2024

Changes:

  • Setup @deriv-com/analytics to integrate feature toggling from Growthbook for enabling/disabling Hydra authentication flow
  • Setup @deriv-com/auth-client to integrate the new Hydra authentication flow
  • Refactored the Deriv iframe localstorage-sync to be enabled/disabled based on the feature flag from Growthbook

Type of change

  • Bug fix
  • New feature
  • Update feature
  • Refactor code
  • Translation to code
  • Translation to crowdin
  • Script configuration
  • Improve performance
  • Style only
  • Dependency update
  • Documentation update
  • Release

@adrienne-deriv adrienne-deriv changed the title Setup auth-client for Hydra authentication Adrienne / Integrate Hydra authentication Sep 26, 2024
const isAuthEnabled = isOAuth2Enabled();

if (!isAuthEnabled) ReactDOM.render(<DerivIFrame />, document.getElementById('deriv_iframe'));
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the DerivIframe component to the javascript folder so that it can be conditionally rendered to be included/excluded based on the feature flag returned by isOauth2Enabled.
If the Hydra authentication is enabled, we will not be using the Deriv iframe to sync login states anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

so we want to disable syncing in certain scenarios?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only disable it when the Hydra authentication feature flag is enabled, which we turn on/off from Growthbook

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because one of our aim for this feature is to remove the use of Deriv iframe sync entirely and migrate these syncing logic into the Hydra service, which is on BE's side

isOAuth2Enabled: function() {
return false
}
});
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 resolve test case issues where @deriv-com/analytics is using Growthbook module which uses MutationObserver, in which Mocha doesn't recognise and is unable to mock it
Screenshot 2024-09-26 at 11 53 04 AM

@adrienne-deriv adrienne-deriv marked this pull request as ready for review September 26, 2024 03:53
@adrienne-deriv adrienne-deriv requested a review from a team as a code owner September 26, 2024 03:53
@@ -22,6 +23,9 @@ jobs:
uses: "./.github/actions/build"
with:
target: production
RUDDERSTACK_KEY: ${{ vars.RUDDERSTACK_KEY }}
GROWTHBOOK_DECRYPTION_KEY: ${{ secrets.GROWTHBOOK_DECRYPTION_KEY }}
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] why is this on secrets but client key is on vars?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Rudderstack and Growthbook client keys are public, you can see them on the network requests and window._growthbook instances, but only the decryption keys are private

export const getOAuthOrigin = () => {
const { appId, serverUrl } = getServerInfo();

const oauthUrl = appId && serverUrl ? `https://${serverUrl}` : DEFAULT_OAUTH_ORIGIN_URL;
Copy link
Contributor

Choose a reason for hiding this comment

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

[Q] whats appId check used here for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its just an extra check to ensure we have the app ID and server URL before returning the origin url

const allowedOrigin = getOAuthOrigin();
if (allowedOrigin === event.origin) {
if (event.data === 'logout_complete') {
await onWSLogoutAndRedirect();
Copy link
Contributor

Choose a reason for hiding this comment

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

[R] please wrap await function in a try catch block


setTimeout(() => {
onWSLogoutAndRedirect();
}, 10000);
Copy link
Contributor

Choose a reason for hiding this comment

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

[M] static data can be put in a constant variable on top of the file

src/javascript/app/base/header.js Show resolved Hide resolved
let checksCounter = 0;
const analyticsInterval = setInterval(() => {
// Check if the analytics instance is available for 10 seconds before setting the feature flag value
if (checksCounter > 20) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why is this required, but i see that this is carried over implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this hook file is no longer needed, will remove it for now 😅

setIsGBLoaded(true);
clearInterval(analyticsInterval);
}
}, 500);
Copy link
Contributor

Choose a reason for hiding this comment

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

[M] this can become 1000 and checksCounter > 10?


const serverUrl = LocalStorageUtils.getValue(LocalStorageConstants.configServerURL) || localStorage.getItem('config.server_url') || 'oauth.deriv.com';

const appId = LocalStorageUtils.getValue(LocalStorageConstants.configAppId);
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 the value always available that we don't need a fallback?

Copy link
Contributor

@amam-deriv amam-deriv left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

Preview Link: https://pr-821.smarttrader-preview.pages.dev

Name Result
Build status Completed ✅
Preview URL Visit Preview
Action URL Visit Action

@ahmadtaimoor-deriv ahmadtaimoor-deriv merged commit 28de573 into deriv-com:master Oct 17, 2024
4 checks passed
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.

6 participants