coder / coder/coder

bug: github device auth never completes if the user doesn't view the coder page with code again

Open
#18,470 0 comments 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
Go
Stars
14.5k
Forks
1.5k
Avg merge
1d 20h
Merged PRs (30d)
601

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Current Behavior

The flow to connect GitHub external auth to Coder using the device flow is as follows:

1. User clicks on the "Login with GitHub" button on https://dev.coder.com/settings/external-auth
2. User is redirected https://dev.coder.com/external-auth/github
3. User copies code, opens GitHub, pastes the code, authorizes Coder
4. User goes back to https://dev.coder.com/external-auth/github. The page polls https://dev.coder.com/api/v2/external-auth/github/device every 5 seconds, which in turn polls GitHub. If the user completed the GitHub authorization process, Coder receives OAuth tokens from GitHub, and saves external auth information in the database.

However, if the user completes step 3 but doesn't move on to step 4, Coder will not poll GitHub and never complete the authentication flow. This can very easily happen on Windows with Chrome when the https://dev.coder.com/external-auth/github page is opened in a pop up window. The user only opens the window to copy the code - there's no natural reason to go back once they complete the flow on GitHub's side. @Jphalan ran into this: he'd go back to https://dev.coder.com/settings/external-auth instead and see a never-ending spinner.

A possible fix is to set `refetchIntervalInBackground: true` on https://github.com/coder/coder/blob/8e3022ed9e42061e6e1d259899be5f4324b1906c/site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx#L44 so that the browser keeps polling Coder even when the user is not looking at the page.

### Relevant Log Output

```shell

```

### Expected Behavior

_No response_

### Steps to Reproduce

See above.

### Environment

- Host OS:
- Coder version:

### Additional Context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.