Skip to content

Commit 3d6651d

Browse files
committed
fix: misleading error after OAuth is disabled
In the edge case where the user disables the OAuth authentication while the authorization page is opened on the server, and then user hits Allow, the URI executes. But the plugin tries to initialize the rest api client and CLI without checking that OAuth is no longer allowed. This raises a misleading error. The fix is somewhat simple, before exchanging the authorization code with an acces token we check if OAuth is still enabled and if not we fail fast with a proper error message. For cases where Cancel is selected by the user on the authorization page we allow the flow to go as usual in Toolbox. - raised coder/coder#24912 while investigating this issue - resolves https://linear.app/codercom/issue/DEVEX-222
1 parent 1081e74 commit 3d6651d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,14 @@ class CoderRemoteProvider(
434434
FAILED_TO_HANDLE_OAUTH2_TITLE,
435435
"OAuth2 server did not respond back with an access token"
436436
)
437-
437+
// before going forward we check to make sure OAuth is not disabled in the meantime
438+
if (!context.settingsStore.preferOAuth2IfAvailable) {
439+
context.logAndShowError(
440+
FAILED_TO_HANDLE_OAUTH2_TITLE,
441+
"OAuth authentication is no longer preferred or enabled for Coder Toolbox. Please use API tokens instead."
442+
)
443+
return
444+
}
438445
exchangeOAuthCodeForToken(code, CoderSetupWizardContext.oauthSession!!)
439446
}
440447

0 commit comments

Comments
 (0)