@civic/nexus-bridge
Version:
Stdio <-> HTTP/SSE MCP bridge with Civic auth handling
45 lines • 1.76 kB
JavaScript
/**
* oidc.ts
*
* Manages OpenID Connect configuration, fetching auth endpoints from
* the well-known discovery URL and providing fallback defaults.
*/
import * as config from './config.js';
import { logger } from "./utils/logger.js";
// Cache for OpenID configuration
let oidcConfig = null;
/**
* Fetch OpenID Connect configuration from the well-known endpoint
* @returns OpenID configuration including auth endpoints
*/
export async function fetchOidcConfig() {
if (oidcConfig) {
return oidcConfig;
}
const wellKnownUrl = `${config.CIVIC_AUTH_URL}/.well-known/openid-configuration`;
logger.info(`Fetching OpenID configuration from ${wellKnownUrl}...`);
try {
const response = await fetch(wellKnownUrl);
if (!response.ok) {
throw new Error(`Failed to fetch OpenID configuration: ${response.status} ${response.statusText}`);
}
oidcConfig = await response.json();
logger.info(`Successfully loaded OpenID configuration, found endpoints:`);
logger.info(`- Authorization: ${oidcConfig.authorization_endpoint}`);
logger.info(`- Token: ${oidcConfig.token_endpoint}`);
return oidcConfig;
}
catch (error) {
console.error(`Error fetching OpenID configuration: ${error}`);
// Fallback to default values if configuration fetch fails
return {
issuer: config.CIVIC_AUTH_URL,
authorization_endpoint: `${config.CIVIC_AUTH_URL}/auth`,
token_endpoint: `${config.CIVIC_AUTH_URL}/token`,
jwks_uri: `${config.CIVIC_AUTH_URL}/jwks`,
response_types_supported: ['code'],
code_challenge_methods_supported: ['S256']
};
}
}
//# sourceMappingURL=oidc.js.map