From 7632d98ba8b9a585551e1894482a2b21713b9344 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Wed, 31 Mar 2021 11:31:56 -0300 Subject: [PATCH] 16159: Passes the token to be expire when calling the logout endpoint. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/services/auth-service/auth-service.ts | 4 ++-- src/store/auth/auth-middleware.test.ts | 2 +- src/store/auth/auth-middleware.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts index 8d27b5bb..bd4bc196 100644 --- a/src/services/auth-service/auth-service.ts +++ b/src/services/auth-service/auth-service.ts @@ -103,9 +103,9 @@ export class AuthService { window.location.assign(`https://${homeClusterHost}/login?${(uuidPrefix !== homeCluster && homeCluster !== loginCluster) ? "remote=" + uuidPrefix + "&" : ""}return_to=${currentUrl}`); } - public logout() { + public logout(expireToken: string) { const currentUrl = `${window.location.protocol}//${window.location.host}`; - window.location.assign(`${this.baseUrl || ""}/logout?return_to=${currentUrl}`); + window.location.assign(`${this.baseUrl || ""}/logout?api_token=${expireToken}&return_to=${currentUrl}`); } public getUserDetails = (showErrors?: boolean): Promise => { diff --git a/src/store/auth/auth-middleware.test.ts b/src/store/auth/auth-middleware.test.ts index bcc942e1..1438cab3 100644 --- a/src/store/auth/auth-middleware.test.ts +++ b/src/store/auth/auth-middleware.test.ts @@ -38,7 +38,7 @@ describe("AuthMiddleware", () => { const middleware = authMiddleware(services)(store)(next); middleware(authActions.LOGOUT({deleteLinkData: false})); expect(window.location.assign).toBeCalledWith( - `/logout?return_to=${location.protocol}//${location.host}` + `/logout?api_token=someToken&return_to=${location.protocol}//${location.host}` ); expect(localStorage.getItem(API_TOKEN_KEY)).toBeFalsy(); }); diff --git a/src/store/auth/auth-middleware.ts b/src/store/auth/auth-middleware.ts index 6eef5e5e..ce7cd5cb 100644 --- a/src/store/auth/auth-middleware.ts +++ b/src/store/auth/auth-middleware.ts @@ -64,11 +64,12 @@ export const authMiddleware = (services: ServiceRepository): Middleware => store if (deleteLinkData) { services.linkAccountService.removeAccountToLink(); } + const token = services.authService.getApiToken(); services.authService.removeApiToken(); services.authService.removeSessions(); services.authService.removeUser(); removeAuthorizationHeader(services); - services.authService.logout(); + services.authService.logout(token || ''); }, default: () => next(action) }); -- 2.30.2