(
_req: IncomingMessage,
res: ServerResponse,
body: LocalOpAuthHostRequest,
)
| 8833 | }, |
| 8834 | ); |
| 8835 | async function handleLocalOpAuthLoginInner( |
| 8836 | _req: IncomingMessage, |
| 8837 | res: ServerResponse, |
| 8838 | body: LocalOpAuthHostRequest, |
| 8839 | ): Promise<void> { |
| 8840 | const host = body.host ?? 'github.com'; |
| 8841 | |
| 8842 | if (!localOpGuard.tryAcquire(LOCAL_OP_AUTH_LOGIN_KEY)) { |
| 8843 | const stale = authLoginInFlight; |
| 8844 | if (!stale) { |
| 8845 | console.error( |
| 8846 | JSON.stringify({ |
| 8847 | event: 'ok-local-op:auth-login-slot-no-controller', |
| 8848 | channel: 'auth', |
| 8849 | transport: 'http', |
| 8850 | }), |
| 8851 | ); |
| 8852 | errorResponse( |
| 8853 | res, |
| 8854 | 429, |
| 8855 | 'urn:ok:error:concurrent-operation', |
| 8856 | 'An auth login operation is already in progress.', |
| 8857 | { handler: HANDLE_LOCAL_OP_AUTH_LOGIN, extraHeaders: { 'Retry-After': '5' } }, |
| 8858 | ); |
| 8859 | return; |
| 8860 | } |
| 8861 | stale.cancel(); |
| 8862 | authLoginInFlight = null; |
| 8863 | console.warn( |
| 8864 | JSON.stringify({ |
| 8865 | event: 'ok-local-op:idempotent-start-replaced-stale-slot', |
| 8866 | channel: 'auth', |
| 8867 | transport: 'http', |
| 8868 | }), |
| 8869 | ); |
| 8870 | } |
| 8871 | |
| 8872 | res.writeHead(200, { |
| 8873 | 'Content-Type': 'application/x-ndjson', |
| 8874 | 'Transfer-Encoding': 'chunked', |
| 8875 | 'X-Content-Type-Options': 'nosniff', |
| 8876 | 'Cache-Control': 'no-cache', |
| 8877 | }); |
| 8878 | |
| 8879 | const writeStreamError = createStreamingErrorWriter(res, HANDLE_LOCAL_OP_AUTH_LOGIN); |
| 8880 | |
| 8881 | const flow = runDeviceFlowSubprocess({ |
| 8882 | cliArgs: localOpCliArgs, |
| 8883 | host, |
| 8884 | timeoutMs: LOCAL_OP_TIMEOUT_MS, |
| 8885 | onEvent: (event: AuthEvent) => { |
| 8886 | if (event.type === 'error') { |
| 8887 | writeStreamError(500, 'urn:ok:error:auth-failed', 'Auth subprocess reported an error.', { |
| 8888 | cause: event.message ? new Error(event.message) : undefined, |
| 8889 | }); |
| 8890 | return; |
| 8891 | } |
| 8892 | resumeSyncOnAuthEvent(event, getSyncEngine); |
nothing calls this directly
no test coverage detected