MCPcopy Index your code
hub / github.com/simstudioai/sim / addInternalAuthIfNeeded

Function addInternalAuthIfNeeded

apps/sim/tools/index.ts:1421–1445  ·  view source on GitHub ↗

* Add internal authentication token to headers if running on server * @param headers - Headers object to modify * @param isInternalRoute - Whether the target URL is an internal route * @param requestId - Request ID for logging * @param context - Context string for logging (e.g., toolId or 'proxy

(
  headers: Headers | Record<string, string>,
  isInternalRoute: boolean,
  requestId: string,
  context: string,
  userId?: string
)

Source from the content-addressed store, hash-verified

1419 * @param context - Context string for logging (e.g., toolId or 'proxy')
1420 */
1421async function addInternalAuthIfNeeded(
1422 headers: Headers | Record<string, string>,
1423 isInternalRoute: boolean,
1424 requestId: string,
1425 context: string,
1426 userId?: string
1427): Promise<void> {
1428 if (typeof window === 'undefined') {
1429 if (isInternalRoute) {
1430 try {
1431 const internalToken = await generateInternalToken(userId)
1432 if (headers instanceof Headers) {
1433 headers.set('Authorization', `Bearer ${internalToken}`)
1434 } else {
1435 headers.Authorization = `Bearer ${internalToken}`
1436 }
1437 logger.info(`[${requestId}] Added internal auth token for ${context}`)
1438 } catch (error) {
1439 logger.error(`[${requestId}] Failed to generate internal token for ${context}:`, error)
1440 }
1441 } else {
1442 logger.info(`[${requestId}] Skipping internal auth token for external URL: ${context}`)
1443 }
1444 }
1445}
1446
1447interface ResolvedRetryConfig {
1448 maxRetries: number

Callers 1

executeToolRequestFunction · 0.85

Calls 4

generateInternalTokenFunction · 0.90
infoMethod · 0.80
errorMethod · 0.80
setMethod · 0.65

Tested by

no test coverage detected