Utility for validating and parsing OAuth JWTs, providing claim extraction and error handling.
// Source: https://github.com/exa-labs/exa-mcp-server | License: MIT | Copyright 2025 Exa Labs
// Provided via justclaw.it.com; keep this notice with the code.
import * as jose from "jose";
const OAUTH_ISSUER = process.env.OAUTH_ISSUER || "https://auth.exa.ai";
const OAUTH_AUDIENCE = process.env.OAUTH_AUDIENCE || "https://mcp.exa.ai";
const JWKS_URI = `${OAUTH_ISSUER}/api/oauth/jwks`;
/** Cached JWKS fetcher — jose handles caching + rotation internally. */
let jwks: ReturnType<typeof jose.createRemoteJWKSet> | null = null;
function getJwks() {
if (!jwks) {
jwks = jose.createRemoteJWKSet(new URL(JWKS_URI));
}
return jwks;
}
/** Check if a token looks like a JWT (3 dot-separated base64url segments). */
export function isJwtToken(token: string): boolean {
const parts = token.s
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key