Skip to content

Commit

Permalink
Revert "[IA-4620] Invalidate Leo token on sign out" (#4621)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcanas authored Jan 30, 2024
1 parent 822f07c commit 7838aef
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 304 deletions.
71 changes: 0 additions & 71 deletions src/analysis/CookieProvider.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/analysis/CookieProvider.ts

This file was deleted.

90 changes: 0 additions & 90 deletions src/auth/auth.test.ts

This file was deleted.

20 changes: 5 additions & 15 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DEFAULT, switchCase } from '@terra-ui-packages/core-utils';
import { parseJSON } from 'date-fns/fp';
import jwtDecode, { JwtPayload } from 'jwt-decode';
import _ from 'lodash/fp';
import { leoCookieProvider } from 'src/analysis/CookieProvider';
import { sessionTimedOutErrorMessage } from 'src/auth/auth-errors';
import {
B2cIdTokenClaims,
Expand All @@ -15,7 +14,7 @@ import {
} from 'src/auth/oidc-broker';
import { cookiesAcceptedKey } from 'src/components/CookieWarning';
import { Ajax } from 'src/libs/ajax';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { fetchOk } from 'src/libs/ajax/ajax-common';
import { SamUserAttributes } from 'src/libs/ajax/User';
import { getSessionStorage } from 'src/libs/browser-storage';
import { withErrorIgnoring, withErrorReporting } from 'src/libs/error';
Expand Down Expand Up @@ -66,7 +65,7 @@ export type SignOutCause =
| 'idleStatusMonitor'
| 'unspecified';

export const sendSignOutMetrics = async (cause: SignOutCause): Promise<void> => {
const sendSignOutMetrics = async (cause: SignOutCause): Promise<void> => {
const eventToFire: MetricsEventName = switchCase<SignOutCause, MetricsEventName>(
cause,
['requested', () => Events.user.signOut.requested],
Expand Down Expand Up @@ -101,26 +100,17 @@ export const sendAuthTokenDesyncMetric = () => {
Ajax().Metrics.captureEvent(Events.user.authToken.desync, {});
};

// This can be called with an expired token, be careful of making any API calls here
// Any API calls that rely on tokens should fail silently
export const signOut = async (cause: SignOutCause = 'unspecified') => {
// The underlying API calls are already wrapped with `withErrorIgnoring`, but we include it here too to be defensive
// It is easier to test this way, and if the underlying API call were to remove that it,
// it would cause a serious bug that is hard for a developer to find/test when the token expires after 24 hours.
await sendSignOutMetrics(cause).catch(_.noop);

export const signOut = (cause: SignOutCause = 'unspecified'): void => {
sendSignOutMetrics(cause);
if (cause === 'expiredRefreshToken' || cause === 'errorRefreshingAuthToken') {
notify('info', sessionTimedOutErrorMessage, sessionTimeoutProps);
}

// TODO: invalidate runtime cookies https://broadworkbench.atlassian.net/browse/IA-3498
cookieReadyStore.reset();
azureCookieReadyStore.reset();
getSessionStorage().clear();

await leoCookieProvider.invalidateCookies();
getSessionStorage().clear();
await revokeTokens().catch(_.noop);
revokeTokens();

const { cookiesAccepted } = authStore.get();

Expand Down
24 changes: 19 additions & 5 deletions src/components/CookieWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import _ from 'lodash/fp';
import { useEffect, useRef, useState } from 'react';
import { aside, div, h } from 'react-hyperscript-helpers';
import { Transition } from 'react-transition-group';
import { leoCookieProvider } from 'src/analysis/CookieProvider';
import { ButtonPrimary, ButtonSecondary, Link } from 'src/components/common';
import { Ajax } from 'src/libs/ajax';
import { getEnabledBrand } from 'src/libs/brand-utils';
import { getSessionStorage } from 'src/libs/browser-storage';
import colors from 'src/libs/colors';
import * as Nav from 'src/libs/nav';
import { useCancellation, useStore } from 'src/libs/react-utils';
import { authStore } from 'src/libs/state';
import { authStore, azureCookieReadyStore, cookieReadyStore } from 'src/libs/state';

export const cookiesAcceptedKey = 'cookiesAccepted';

Expand All @@ -22,10 +22,10 @@ const transitionStyle = {

const CookieWarning = () => {
const animTime = 0.3;
const signal = useCancellation();
const [showWarning, setShowWarning] = useState(false);
const { cookiesAccepted } = useStore(authStore);
const timeout = useRef();
const signal = useCancellation();
const brand = getEnabledBrand();

const acceptCookies = (acceptedCookies) => {
Expand All @@ -45,9 +45,23 @@ const CookieWarning = () => {
}, [cookiesAccepted]);

const rejectCookies = async () => {
await leoCookieProvider.invalidateCookies({ signal });
getSessionStorage().clear();
const cookies = document.cookie.split(';');
acceptCookies(false);
// TODO: call azure invalidate cookie once endpoint exists, https://broadworkbench.atlassian.net/browse/IA-3498
await Ajax(signal)
.Runtimes.invalidateCookie()
.catch(() => {});
// Expire all cookies
_.forEach((cookie) => {
// Find an equals sign and uses it to grab the substring of the cookie that is its name
const eqPos = cookie.indexOf('=');
const cookieName = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = `${cookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;
}, cookies);

cookieReadyStore.reset();
azureCookieReadyStore.reset();
getSessionStorage().clear();
};

return h(
Expand Down
2 changes: 1 addition & 1 deletion src/components/ImageDepViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash/fp';
import { Fragment, useEffect, useState } from 'react';
import { div, h, table, tbody, td, thead, tr } from 'react-hyperscript-helpers';
import { Select } from 'src/components/common';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { fetchOk } from 'src/libs/ajax/ajax-common';
import { withErrorReporting } from 'src/libs/error';
import { useCancellation } from 'src/libs/react-utils';

Expand Down
2 changes: 1 addition & 1 deletion src/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fetchDrsHub,
fetchGoogleForms,
fetchMartha,
fetchOk,
fetchOrchestration,
fetchRawls,
jsonBody,
Expand All @@ -22,7 +23,6 @@ import { Apps } from 'src/libs/ajax/leonardo/Apps';
import { Disks } from 'src/libs/ajax/leonardo/Disks';
import { Runtimes } from 'src/libs/ajax/leonardo/Runtimes';
import { Metrics } from 'src/libs/ajax/Metrics';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { OAuth2 } from 'src/libs/ajax/OAuth2';
import { SamResources } from 'src/libs/ajax/SamResources';
import { Support } from 'src/libs/ajax/Support';
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ajax/AzureStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { AnalysisFile, AnalysisFileMetadata } from 'src/analysis/useAnalysisFile
import { AbsolutePath, getDisplayName, getExtension, getFileName } from 'src/analysis/utils/file-utils';
import { runtimeToolLabels } from 'src/analysis/utils/tool-utils';
import { Ajax } from 'src/libs/ajax';
import { authOpts, fetchWorkspaceManager } from 'src/libs/ajax/ajax-common';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { authOpts, fetchOk, fetchWorkspaceManager } from 'src/libs/ajax/ajax-common';
import { getConfig } from 'src/libs/config';
import * as Utils from 'src/libs/utils';
import { cloudProviderTypes } from 'src/libs/workspace-utils';
Expand Down
13 changes: 2 additions & 11 deletions src/libs/ajax/Dockstore.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { asMockedFn } from 'src/testing/test-utils';

import { fetchDockstore } from './ajax-common';
import { fetchDockstore, fetchOk } from './ajax-common';
import { Dockstore } from './Dockstore';

type AjaxCommonExports = typeof import('./ajax-common');
jest.mock('./ajax-common', (): Partial<AjaxCommonExports> => {
return {
fetchDockstore: jest.fn(),
fetchOk: jest.fn(),
};
});

type FetchCoreExports = typeof import('src/libs/ajax/network-core/fetch-core');
jest.mock(
'src/libs/ajax/network-core/fetch-core',
(): FetchCoreExports => ({
...jest.requireActual<FetchCoreExports>('src/libs/ajax/network-core/fetch-core'),
fetchOk: jest.fn(),
})
);

describe('Dockstore', () => {
afterEach(() => {
jest.resetAllMocks();
Expand Down
3 changes: 1 addition & 2 deletions src/libs/ajax/Dockstore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as qs from 'qs';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';

import { fetchDockstore } from './ajax-common';
import { fetchDockstore, fetchOk } from './ajax-common';

export type DockstoreWorkflowDescriptor = {
path: string;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ajax/GoogleStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { getAuthToken } from 'src/auth/auth';
import {
authOpts,
checkRequesterPaysError,
fetchOk,
fetchSam,
jsonBody,
withRetryOnError,
withUrlPrefix,
} from 'src/libs/ajax/ajax-common';
import { canUseWorkspaceProject } from 'src/libs/ajax/Billing';
import { fetchOk } from 'src/libs/ajax/network-core/fetch-core';
import { getConfig } from 'src/libs/config';
import { knownBucketRequesterPaysStatuses, requesterPaysProjectStore, workspaceStore } from 'src/libs/state';
import * as Utils from 'src/libs/utils';
Expand Down
1 change: 0 additions & 1 deletion src/libs/ajax/Metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,3 @@ export const Metrics = (signal?: AbortSignal) => {
}) as (anonId: string) => Promise<void>,
};
};
export type MetricsContract = ReturnType<typeof Metrics>;
Loading

0 comments on commit 7838aef

Please sign in to comment.