mirror of
https://github.com/prowler-cloud/prowler.git
synced 2025-12-19 05:17:47 +00:00
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>
29 lines
789 B
TypeScript
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;
|
|
}
|