Skip to content

feat(IDE-1701): settings page auth flow — bridge persist and forward apiUrl#795

Open
nick-y-snyk wants to merge 2 commits intomasterfrom
feat/generic-webview-execute-command-bridge
Open

feat(IDE-1701): settings page auth flow — bridge persist and forward apiUrl#795
nick-y-snyk wants to merge 2 commits intomasterfrom
feat/generic-webview-execute-command-bridge

Conversation

@nick-y-snyk
Copy link
Contributor

@nick-y-snyk nick-y-snyk commented Mar 5, 2026

What & Why

The settings page drives authentication via snyk.login with [authMethod, endpoint, insecure] args. Before forwarding to the LS, the IDE must persist these values locally so they survive a page close. Additionally, $/snyk.hasAuthenticated now carries apiUrl which is forwarded to the settings panel webview so the settings page can update both fields after auth.

Bridge persist written directly to pluginSettings() properties — no updateConfiguration() call means no didChangeConfiguration loop.

Changes

ExecuteCommandBridge.kt (new shared class)

  • LOGIN_TIMEOUT_MS = 120_000L; LONG_RUNNING_COMMANDS = setOf("snyk.login") — login waits up to 2 min for browser OAuth
  • Replaces __ideLogin__/__ideLogout__ with window.__ideExecuteCommand__(cmd, args, callback) bridge
  • Before ls.executeCommandWithArgs, when command == "snyk.login" and args.size >= 3, calls saveLoginArgs(args):
    • Maps args[0]AuthenticationType ("oauth"OAUTH2, "pat"PAT, "token"API_TOKEN)
    • Sets pluginSettings().authenticationType, .customEndpointUrl, .ignoreUnknownCA
    • No updateConfiguration() call → no didChangeConfiguration sent to LS
  • LanguageServerWrapper.executeCommandWithArgs gains timeoutMillis: Long = 5_000 param

HTMLSettingsPanel.kt

  • companion object { @Volatile var instance: HTMLSettingsPanel? = null } — set in init, cleared in dispose()
  • setAuthToken(token: String, apiUrl: String?) — escapes both, executes window.setAuthToken(safeToken, safeApiUrl) via JCEF on invokeLater with ModalityState.any()

SnykLanguageClient.kt
Calls HTMLSettingsPanel.instance?.setAuthToken(param.token ?: "", param.apiUrl) before saving to pluginSettings() — settings page webview updates immediately after auth.

SaveConfigHandler.kt
Removes the messageBus.subscribe(SnykSettingsListener.SNYK_SETTINGS_TOPIC, ...) block that pushed token updates to the browser — replaced by the direct HTMLSettingsPanel.instance?.setAuthToken(...) call in SnykLanguageClient.

Tests

  • SaveConfigHandlerExecuteCommandTest.kt: bridge persist test added (sends snyk.login with ["pat", "https://api.eu.snyk.io", true], asserts authenticationType == PAT, customEndpointUrl, ignoreUnknownCA); all executeCommandWithArgs verify calls include timeout arg
  • SnykLanguageClientTest.kt: setAuthToken called on HTMLSettingsPanel.instance when panel is open (new test)

Test plan

  • Settings page: change endpoint + auth method → click Authenticate → IDE saves values → auth succeeds → token and apiUrl appear in settings page
  • Close/reopen settings page → values persist
  • Panel login → auth succeeds → token and apiUrl shown immediately
  • No didChangeConfiguration sent when bridge saves auth params
  • Run test suite: ./gradlew test

…rotocol version to 25 [IDE-1701]

- Add ExecuteCommandBridge class as the single shared implementation of the
  __ideExecuteCommand__ JS↔IDE contract, used by both the HTML tree view and
  the settings page
- Remove duplicated bridge script and dispatch logic from SaveConfigHandler and
  TreeViewBridgeHandler; both now delegate to ExecuteCommandBridge
- Remove ALLOWED_COMMANDS allowlist from TreeViewBridgeHandler — the LS-generated
  HTML is trusted and both panels now share the same open bridge
- Add SaveConfigHandlerExecuteCommandTest covering snyk.login/snyk.logout routing
  and callback invocation
- Bump requiredLsProtocolVersion 24 → 25
… flag

- Remove persist field from HasAuthenticatedParam — always saves token and apiUrl
- Revert persist conditional in hasAuthenticated — always writes to pluginSettings
  and triggers scan on first login (blank old token)
- Add HTMLSettingsPanel.instance static reference for direct token injection
- Add setAuthToken(token, apiUrl) on HTMLSettingsPanel — called from hasAuthenticated
  so the settings page webview shows the token immediately after auth
- Remove updateConfiguration(false) call before snyk.login in ExecuteCommandBridge
- Add bridge persist in ExecuteCommandBridge.dispatch: when snyk.login called with
  3+ args, save authMethod/endpoint/ignoreUnknownCA to pluginSettings before
  forwarding to LS (no updateConfiguration → no didChangeConfiguration loop)
- Remove updateConfiguration test; add bridge persist test verifying settings written
- Remove persist-related tests from SnykLanguageClientTest; keep setAuthToken test
- Extend executeCommandWithArgs timeout param to support 120s for snyk.login
@nick-y-snyk nick-y-snyk requested review from a team as code owners March 5, 2026 17:47
@snyk-io
Copy link

snyk-io bot commented Mar 5, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

@nick-y-snyk nick-y-snyk changed the title feat(IDE-1701): settings page auth flow — bridge persist and remove persist flag feat(IDE-1701): settings page auth flow — bridge persist and forward apiUrl Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant