MCPcopy Index your code
hub / github.com/coder/mux / pollGithubDeviceFlow

Method pollGithubDeviceFlow

src/node/services/serverAuthService.ts:602–698  ·  view source on GitHub ↗
(flow: GithubDeviceFlow)

Source from the content-addressed store, hash-verified

600 }
601
602 private async pollGithubDeviceFlow(flow: GithubDeviceFlow): Promise<void> {
603 while (!flow.cancelled) {
604 try {
605 const tokenResult = await this.pollGithubAccessToken(flow);
606 if (flow.cancelled) {
607 return;
608 }
609
610 if (!tokenResult.success) {
611 this.finishGithubDeviceFlow(flow.flowId, Err(tokenResult.error));
612 return;
613 }
614
615 if (tokenResult.data.type === "pending") {
616 // Continue polling.
617 } else if (tokenResult.data.type === "slow_down") {
618 flow.intervalSeconds = tokenResult.data.intervalSeconds;
619 } else if (tokenResult.data.type === "authorized") {
620 const loginResult = await this.fetchGithubLogin(tokenResult.data.accessToken);
621 if (flow.cancelled) {
622 return;
623 }
624
625 if (!loginResult.success) {
626 this.finishGithubDeviceFlow(flow.flowId, Err(loginResult.error));
627 return;
628 }
629
630 const allowedOwner = this.getAllowedGithubOwner();
631 if (!allowedOwner) {
632 this.finishGithubDeviceFlow(
633 flow.flowId,
634 Err("GitHub owner login is no longer configured")
635 );
636 return;
637 }
638
639 if (loginResult.data.toLowerCase() !== allowedOwner.toLowerCase()) {
640 this.finishGithubDeviceFlow(
641 flow.flowId,
642 Err(`GitHub user '${loginResult.data}' is not authorized for this server`)
643 );
644 return;
645 }
646
647 if (flow.cancelled) {
648 return;
649 }
650
651 const sessionResult = await this.createSessionLocked({
652 userAgent: flow.userAgent,
653 ipAddress: flow.ipAddress,
654 });
655
656 if (flow.cancelled) {
657 // The flow may be canceled while a session write is in progress.
658 // Defensive cleanup avoids orphan sessions that have no delivered token.
659 if (sessionResult.success) {

Callers 1

Calls 9

pollGithubAccessTokenMethod · 0.95
fetchGithubLoginMethod · 0.95
getAllowedGithubOwnerMethod · 0.95
createSessionLockedMethod · 0.95
revokeSessionMethod · 0.95
ErrFunction · 0.90
OkFunction · 0.90
getErrorMessageFunction · 0.90

Tested by

no test coverage detected