MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / pollDeviceAuthCode

Function pollDeviceAuthCode

apps/extension/src/shared/auth.ts:159–189  ·  view source on GitHub ↗
({
  apiBaseUrl,
  code,
  fetch,
  signal,
}: PollDeviceAuthCodeOptions)

Source from the content-addressed store, hash-verified

157};
158
159export const pollDeviceAuthCode = async ({
160 apiBaseUrl,
161 code,
162 fetch,
163 signal,
164}: PollDeviceAuthCodeOptions): Promise<DeviceAuthPollResult> => {
165 const requestInit: RequestInit = signal === undefined ? {} : { signal };
166 const response = await fetch(
167 `${trimTrailingSlash(apiBaseUrl)}/api/device-auth/codes/${encodeURIComponent(code)}`,
168 requestInit
169 );
170
171 switch (response.status) {
172 case 200: {
173 const data: unknown = await response.json();
174 return { auth: parseApprovedAuth(data), status: 'approved' };
175 }
176 case 202: {
177 return { status: 'pending' };
178 }
179 case 403: {
180 return { status: 'denied' };
181 }
182 case 410: {
183 return { status: 'expired' };
184 }
185 default: {
186 throw new Error('Failed to check sign-in status.');
187 }
188 }
189};
190
191export const validateAuthToken = async ({
192 apiBaseUrl,

Callers 2

AppFunction · 0.90
pollWithResponseFunction · 0.90

Calls 4

parseApprovedAuthFunction · 0.85
fetchFunction · 0.70
trimTrailingSlashFunction · 0.70
jsonMethod · 0.65

Tested by 1

pollWithResponseFunction · 0.72