MCPcopy Index your code
hub / github.com/callstack/agent-device / resolveRequestToken

Function resolveRequestToken

src/remote/daemon-proxy.ts:347–359  ·  view source on GitHub ↗
(req: IncomingMessage, rpcBody: string | undefined)

Source from the content-addressed store, hash-verified

345}
346
347function resolveRequestToken(req: IncomingMessage, rpcBody: string | undefined): string {
348 const authHeader = typeof req.headers.authorization === 'string' ? req.headers.authorization : '';
349 if (authHeader.toLowerCase().startsWith('bearer ')) {
350 return authHeader.slice('bearer '.length);
351 }
352 const tokenHeader = req.headers['x-agent-device-token'];
353 if (typeof tokenHeader === 'string') return tokenHeader;
354 if (rpcBody) {
355 const bodyToken = readJsonRpcToken(rpcBody);
356 if (bodyToken) return bodyToken;
357 }
358 return '';
359}
360
361function rewriteRpcToken(body: string, upstreamToken: string): string {
362 const parsed = JSON.parse(body) as { params?: Record<string, unknown> };

Callers 1

isAuthorizedFunction · 0.85

Calls 2

readJsonRpcTokenFunction · 0.85
startsWithMethod · 0.80

Tested by

no test coverage detected