openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
26 lines (25 loc) • 1.52 kB
JavaScript
import { f as loadAuthProfileStoreForRuntimeAsync } from "../store-runtime-dW0pXLJI.mjs";
import { n as resolveApiKeyForProfile } from "../oauth--EeX6RHc.mjs";
//#region src/agents/mcp-auth-profile.runtime.ts
async function resolveMcpAuthProfileBearerToken(e) {
const t = await loadAuthProfileStoreForRuntimeAsync(e.agentDir, {
config: e.cfg,
externalCliProfileIds: [e.profileId],
readOnly: true,
allowKeychainPrompt: false
});
const n = t.profiles[e.profileId];
if (!n) throw new Error(`MCP server "${e.serverName}" references auth profile "${e.profileId}", but that profile was not found.`);
if (n.type !== "oauth") throw new Error(`MCP server "${e.serverName}" references auth profile "${e.profileId}", but ${n.type} profiles are not refreshable. Use a refresh-capable OAuth profile.`);
const r = await resolveApiKeyForProfile({
cfg: e.cfg,
store: t,
profileId: e.profileId,
agentDir: e.agentDir
});
if (!r || r.profileType !== "oauth" || !r.apiKey) throw new Error(`MCP server "${e.serverName}" could not resolve refreshable OAuth auth profile "${e.profileId}". Re-authenticate the profile and retry.`);
if (!r.credential || r.credential.type !== "oauth" || typeof r.credential.access !== "string" || r.credential.access.trim().length === 0) throw new Error(`MCP server "${e.serverName}" resolved OAuth auth profile "${e.profileId}", but no raw access token was available for bearer projection.`);
return r.credential.access;
}
//#endregion
export { resolveMcpAuthProfileBearerToken };