Files
prowler/ui/lib/lighthouse/auth-context.ts
Chandrapal Badshah b9bfdc1a5a feat: Integrate Prowler MCP to Lighthouse AI (#9255)
Co-authored-by: Chandrapal Badshah <12944530+Chan9390@users.noreply.github.com>
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
Co-authored-by: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com>
Co-authored-by: Alan Buscaglia <gentlemanprogramming@gmail.com>
Co-authored-by: Adrián Jesús Peña Rodríguez <adrianjpr@gmail.com>
Co-authored-by: Andoni Alonso <14891798+andoniaf@users.noreply.github.com>
Co-authored-by: Rubén De la Torre Vico <ruben@prowler.com>
Co-authored-by: Daniel Barranquero <danielbo2001@gmail.com>
2025-12-17 10:10:43 +01:00

29 lines
789 B
TypeScript

import "server-only";
import { AsyncLocalStorage } from "async_hooks";
/**
* AsyncLocalStorage instance for storing the access token in the current async context.
* This enables authentication to flow through MCP tool calls without explicit parameter passing.
*
* @remarks This module is server-only as it uses Node.js AsyncLocalStorage
*/
export const authContextStorage = new AsyncLocalStorage<string>();
/**
* Retrieves the access token from the current async context.
*
* @returns The access token if available, null otherwise
*
* @example
* ```typescript
* const token = getAuthContext();
* if (token) {
* headers.Authorization = `Bearer ${token}`;
* }
* ```
*/
export function getAuthContext(): string | null {
return authContextStorage.getStore() ?? null;
}