Skip to content

Commit

Permalink
Revert "[IA-4620] invalidate cookies on sign out" (#4577)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdcanas authored Jan 5, 2024
1 parent 5189b74 commit 8090b19
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 74 deletions.
14 changes: 8 additions & 6 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
OidcUser,
revokeTokens,
} from 'src/auth/oidc-broker';
import { cookieProvider } from 'src/components/CookieProvider';
import { cookiesAcceptedKey } from 'src/components/CookieWarning';
import { Ajax } from 'src/libs/ajax';
import { fetchOk } from 'src/libs/ajax/ajax-common';
Expand All @@ -28,7 +27,9 @@ import {
asyncImportJobStore,
AuthState,
authStore,
azureCookieReadyStore,
azurePreviewStore,
cookieReadyStore,
getTerraUser,
MetricState,
metricStore,
Expand Down Expand Up @@ -100,17 +101,18 @@ export const sendAuthTokenDesyncMetric = () => {
Ajax().Metrics.captureEvent(Events.user.authToken.desync, {});
};

export const signOut = async (cause: SignOutCause = 'unspecified') => {
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();
azurePreviewStore.set(false);

await cookieProvider.invalidateCookies();
getSessionStorage().clear();
await revokeTokens();
revokeTokens();

const { cookiesAccepted } = authStore.get();

Expand Down
44 changes: 0 additions & 44 deletions src/components/CookieProvider.test.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/components/CookieProvider.ts

This file was deleted.

24 changes: 19 additions & 5 deletions src/components/CookieWarning.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { useEffect, useRef, useState } from 'react';
import { aside, div, h } from 'react-hyperscript-helpers';
import { Transition } from 'react-transition-group';
import { ButtonPrimary, ButtonSecondary, Link } from 'src/components/common';
import { cookieProvider } from 'src/components/CookieProvider';
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 cookieProvider.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/libs/ajax/leonardo/Runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const Runtimes = (signal: AbortSignal) => {
},

invalidateCookie: () => {
return fetchLeo('proxy/invalidateToken', _.merge(authOpts(), { signal, credentials: 'include' }));
return fetchLeo('proxy/invalidateToken', _.merge(authOpts(), { signal }));
},

setCookie: () => {
Expand Down

0 comments on commit 8090b19

Please sign in to comment.