diff --git a/media/auth.js b/media/auth.js index 29dc98a97..e060cd9a3 100644 --- a/media/auth.js +++ b/media/auth.js @@ -29,6 +29,8 @@ }); authButton.addEventListener("click", () => { + messageBox.style.display = "none"; + vscode.postMessage({ command: "authenticate", authMethod: document.querySelector('input[name="authMethod"]:checked') diff --git a/src/cx/cx.ts b/src/cx/cx.ts index 33123d17f..b5ce7ad61 100644 --- a/src/cx/cx.ts +++ b/src/cx/cx.ts @@ -287,7 +287,6 @@ export class Cx implements CxPlatform { async getAstConfiguration() { const token = await this.context.secrets.get("authCredential"); - console.log("Token from secrets:", token); if (!token) { return undefined; diff --git a/src/cx/cxMock.ts b/src/cx/cxMock.ts index cf2c1135c..b12d44f4a 100644 --- a/src/cx/cxMock.ts +++ b/src/cx/cxMock.ts @@ -1299,7 +1299,6 @@ export class CxMock implements CxPlatform { async getAstConfiguration() { const token = await this.context.secrets.get("authCredential"); - console.log("Token from secrets:", token); if (!token) { return undefined; diff --git a/src/extension.ts b/src/extension.ts index 8bea6638f..9ed90d201 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -240,7 +240,7 @@ export async function activate(context: vscode.ExtensionContext) { vscode.commands.registerCommand("ast-results.mockTokenTest", async () => { const authService = AuthService.getInstance(context); await authService.saveToken(context, "FAKE_TOKEN_FROM_TEST"); - console.log(">> Mock token has been saved to secrets"); // שורת לוג + console.log(">> Mock token has been saved to secrets"); await authService.validateAndUpdateState(); }); diff --git a/src/services/authService.ts b/src/services/authService.ts index 54f1efb5f..b8b5060f3 100644 --- a/src/services/authService.ts +++ b/src/services/authService.ts @@ -174,7 +174,7 @@ private async checkUrlExists(urlToCheck: string, isTenantCheck = false): Promise authEndpoint: `${baseUri}/auth/realms/${tenant}/protocol/openid-connect/auth`, tokenEndpoint: `${baseUri}/auth/realms/${tenant}/protocol/openid-connect/token`, redirectUri: `http://localhost:${port}/checkmarx1/callback`, - scope: 'openid', + scope: 'openid offline_access', codeVerifier, codeChallenge, port @@ -182,16 +182,20 @@ private async checkUrlExists(urlToCheck: string, isTenantCheck = false): Promise try { const server = await this.startLocalServer(config); - vscode.env.openExternal(vscode.Uri.parse( - `${config.authEndpoint}?` + - `client_id=${config.clientId}&` + - `redirect_uri=${encodeURIComponent(config.redirectUri)}&` + - `response_type=code&` + - `scope=${config.scope}&` + - `code_challenge=${config.codeChallenge}&` + - `code_challenge_method=S256` - )); - + + const authUrl = `${config.authEndpoint}?` + + `client_id=${config.clientId}&` + + `redirect_uri=${encodeURIComponent(config.redirectUri)}&` + + `response_type=code&` + + `scope=${config.scope}&` + + `code_challenge=${config.codeChallenge}&` + + `code_challenge_method=S256`; + + const opened = await vscode.env.openExternal(vscode.Uri.parse(authUrl)); + if (!opened) { + server.close(); + return ""; + } // Now we get both the code and response object const { code, res } = await this.waitForCode(server); const token = await this.getRefreshToken(code, config); @@ -526,7 +530,6 @@ private async checkUrlExists(urlToCheck: string, isTenantCheck = false): Promise