diegosouzapw/OmniRoute · error

encodeCredentialBlob: tokens object is required

Error message

encodeCredentialBlob: tokens object is required

What it means

decodeCredentialBlob stripped the prefix and the remaining payload failed the base64url charset check (/^[A-Za-z0-9_-]+$/). The blob is corrupted or hand-edited: it contains characters outside the URL-safe base64 alphabet (e.g. +, /, spaces) or trailing padding. Detected before any decoding is attempted.

Solutions

  1. Pass the raw OAuth token response object as tokens
  2. Check for null tokens before calling the encoder
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/lib/oauth/credentialBlob.ts:52 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25). Data as JSON: /api/errors/3c3946dfa267b2b9. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/oauth/credentialBlob.ts:52

  scope?: string;
  [key: string]: unknown;
}

export interface CredentialBlob {
  provider: string;
  tokens: CredentialBlobTokens;
}

/**
 * Encode a provider + raw OAuth token response into a single-line blob.
 * Throws if `provider` is missing — a blob with no provider cannot be routed.
 */
export function encodeCredentialBlob(input: CredentialBlob): string {
  if (!input || typeof input.provider !== "string" || !input.provider.trim()) {
    throw new Error("encodeCredentialBlob: a non-empty provider is required");
  }
  if (!input.tokens || typeof input.tokens !== "object") {
    throw new Error("encodeCredentialBlob: tokens object is required");
  }
  const payload = {
    v: CREDENTIAL_BLOB_VERSION,
    provider: input.provider.trim(),
    tokens: input.tokens,
  };
  const json = JSON.stringify(payload);
  const b64 = Buffer.from(json, "utf8").toString("base64url");
  return `${CREDENTIAL_BLOB_PREFIX}${b64}`;
}

/**
 * Decode a credential blob produced by {@link encodeCredentialBlob}.
 * Validates the prefix, version, JSON shape, and the presence of an access_token.
 * Throws a descriptive error on any malformed/tampered/unsupported input.
 */
export function decodeCredentialBlob(blob: string): CredentialBlob {
  if (typeof blob !== "string" || !blob.startsWith(CREDENTIAL_BLOB_PREFIX)) {

View on GitHub (pinned to a179ffed5b)