From dfb714b3dfc9c8fcef9ff82ebbcfbb114a172a21 Mon Sep 17 00:00:00 2001 From: Christian Zheng <czheng@takima.fr> Date: Tue, 12 Apr 2022 12:02:46 +0200 Subject: [PATCH] fix(login): repair unconsistency on logged state --- .../deadlock-extension/src/core/controller.ts | 9 ++++----- .../src/core/keycloakOAuth2DeviceFlowConnection.ts | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/deadlock-plugins/deadlock-extension/src/core/controller.ts b/deadlock-plugins/deadlock-extension/src/core/controller.ts index af61def6..afee4a86 100644 --- a/deadlock-plugins/deadlock-extension/src/core/controller.ts +++ b/deadlock-plugins/deadlock-extension/src/core/controller.ts @@ -51,6 +51,9 @@ export default class Controller { } async authenticate() { + // WARN generate a new device code every time student clicks on log in button. Should I keep it ?\ + // The answer might be 'yes' because when the student is already authenticated, the log in button should be disabled. + await this.connection.registerDevice(); const tokens = await this.connection.getToken({ openLink: Controller.openBrowserWithUrl }); const exensionStorage = ExtensionStore.getInstance(); await exensionStorage.setAccessToken(tokens.accessToken); @@ -74,11 +77,7 @@ export default class Controller { console.log('accesToke: ' + extensionStore.getAccessToken()); if (!hadBeenConnected) { - const { accessToken, refreshToken } = await this.connection.getToken({ - openLink: Controller.openBrowserWithUrl, - }); - extensionStore.setAccessToken(accessToken); - extensionStore.setRefreshToken(refreshToken); + this.authenticate(); vscode.window.showInformationMessage('Nouvelle connexion validée'); } else { vscode.window.showInformationMessage('Déjà connecté: session récupérée'); diff --git a/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts b/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts index 7a345876..64dbea20 100644 --- a/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts +++ b/deadlock-plugins/deadlock-extension/src/core/keycloakOAuth2DeviceFlowConnection.ts @@ -77,7 +77,7 @@ export default class KeycloakOAuth2DeviceFlowConnection { return Promise.resolve({ accessToken: this._accessToken, refreshToken: this._refreshToken }); } if (!this._deviceIsRegistered()) { - await this._registerDevice(); + await this.registerDevice(); } try { openLink(this._deviceAuthorizationRequestResponseData.verification_uri_complete!); @@ -103,7 +103,7 @@ export default class KeycloakOAuth2DeviceFlowConnection { return !!this._deviceAuthorizationRequestResponseData.device_code; } - private async _registerDevice() { + public async registerDevice() { log('Device not registered. Registering ...'); const deviceAuthorizationRequestResponse: Response = await this.createDeviceAuthorization({ url: this._deviceUrl, -- GitLab