Skip to content

fix: misleading error after OAuth is disabled#299

Merged
fioan89 merged 2 commits intomainfrom
fix-misleading-error-after-disabling-oauth
May 4, 2026
Merged

fix: misleading error after OAuth is disabled#299
fioan89 merged 2 commits intomainfrom
fix-misleading-error-after-disabling-oauth

Conversation

@fioan89
Copy link
Copy Markdown
Collaborator

@fioan89 fioan89 commented May 1, 2026

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.

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
"OAuth2 server did not respond back with an access token"
)

// before going forward we check to make sure OAuth is not disabled in the meantime
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does disabling mean here? Disabled on the server or the user has not enabled it in the plugin settings?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means disabled in the plugin.

Comment thread src/main/kotlin/com/coder/toolbox/CoderRemoteProvider.kt Outdated
Copy link
Copy Markdown

@zenithwolf1000 zenithwolf1000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable to me!


// before going forward we check to make sure OAuth is not disabled in the meantime
if (!context.settingsStore.preferOAuth2IfAvailable) {
context.logAndShowError(
Copy link
Copy Markdown

@jeremyruppel jeremyruppel May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other cases in this function return context.logAndShowError(), but here we have the log and then an empty return. should we care about the return? or perhaps it's a good idea to be consistent about the return?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other cases I used the elvis operator and a little trick from Kotlin that allows return statements to exit early if an expression does not match a certain value (in the particular cases if some variables have non null values). logAndShowError is a "void" function. Technically void functions in Kotlin always return a Unit type. And then Unit allows the trick of writing return Unit which causes the enclosing function to exit early.

In this case particular case I can't do that trick.

@fioan89 fioan89 merged commit 8d2a2aa into main May 4, 2026
6 checks passed
@fioan89 fioan89 deleted the fix-misleading-error-after-disabling-oauth branch May 4, 2026 19:34
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.

4 participants