MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / fetchRemoteCredentials

Function fetchRemoteCredentials

source code/bridge/codeSessionApi.ts:95–170  ·  view source on GitHub ↗
(
  sessionId: string,
  baseUrl: string,
  accessToken: string,
  timeoutMs: number,
  trustedDeviceToken?: string,
)

Source from the content-addressed store, hash-verified

93}
94
95export async function fetchRemoteCredentials(
96 sessionId: string,
97 baseUrl: string,
98 accessToken: string,
99 timeoutMs: number,
100 trustedDeviceToken?: string,
101): Promise<RemoteCredentials | null> {
102 const url = `${baseUrl}/v1/code/sessions/${sessionId}/bridge`
103 const headers = oauthHeaders(accessToken)
104 if (trustedDeviceToken) {
105 headers['X-Trusted-Device-Token'] = trustedDeviceToken
106 }
107 let response
108 try {
109 response = await axios.post(
110 url,
111 {},
112 {
113 headers,
114 timeout: timeoutMs,
115 validateStatus: s => s < 500,
116 },
117 )
118 } catch (err: unknown) {
119 logForDebugging(
120 `[code-session] /bridge request failed: ${errorMessage(err)}`,
121 )
122 return null
123 }
124
125 if (response.status !== 200) {
126 const detail = extractErrorDetail(response.data)
127 logForDebugging(
128 `[code-session] /bridge failed ${response.status}${detail ? `: ${detail}` : ''}`,
129 )
130 return null
131 }
132
133 const data: unknown = response.data
134 if (
135 data === null ||
136 typeof data !== 'object' ||
137 !('worker_jwt' in data) ||
138 typeof data.worker_jwt !== 'string' ||
139 !('expires_in' in data) ||
140 typeof data.expires_in !== 'number' ||
141 !('api_base_url' in data) ||
142 typeof data.api_base_url !== 'string' ||
143 !('worker_epoch' in data)
144 ) {
145 logForDebugging(
146 `[code-session] /bridge response malformed (need worker_jwt, expires_in, api_base_url, worker_epoch): ${jsonStringify(data).slice(0, 200)}`,
147 )
148 return null
149 }
150 // protojson serializes int64 as a string to avoid JS precision loss;
151 // Go may also return a number depending on encoder settings.
152 const rawEpoch = data.worker_epoch

Callers

nothing calls this directly

Calls 5

logForDebuggingFunction · 0.85
extractErrorDetailFunction · 0.85
jsonStringifyFunction · 0.85
oauthHeadersFunction · 0.70
errorMessageFunction · 0.50

Tested by

no test coverage detected