Skip to content

fix(auth): accept BRIGHTDATA_API_TOKEN / API_TOKEN as API-key fallbacks#17

Open
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/api-token-env-fallback
Open

fix(auth): accept BRIGHTDATA_API_TOKEN / API_TOKEN as API-key fallbacks#17
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/api-token-env-fallback

Conversation

@danishashko

Copy link
Copy Markdown

Problem

resolve_api_key (src/utils/config.ts) only read BRIGHTDATA_API_KEY. But the Bright Data MCP and the reference SDKs export the same secret as BRIGHTDATA_API_TOKEN, and this CLI's own add-mcp command writes the key into the generated MCP config as API_TOKEN. So anyone driving the CLI from that same environment (an agent, or a developer who set up the MCP) hits No API key found on the very first call.

Fix

Fall back BRIGHTDATA_API_KEYBRIGHTDATA_API_TOKENAPI_TOKEN. Precedence is preserved (an explicit --api-key and BRIGHTDATA_API_KEY still win), and empty-string env vars are ignored, matching the previous behaviour. The "No API key found" message is updated to mention the accepted variables.

Tests

  • Added resolve_api_key cases: fallback order, precedence, empty-string handling, and the undefined case.
  • Hardened the add-mcp test to clear all three vars in setup so it stays hermetic regardless of the caller's environment (it previously cleared only BRIGHTDATA_API_KEY).

Verified: tsc clean, full test suite passes with no new failures, and the built binary authenticates against the live API with only BRIGHTDATA_API_TOKEN set.

resolve_api_key only read BRIGHTDATA_API_KEY, but the Bright Data MCP and
reference SDKs export the same secret as BRIGHTDATA_API_TOKEN, and the CLI's
own add-mcp writes API_TOKEN into the MCP configs it generates. Anyone driving
the CLI from that environment hit "No API key found" on the very first call.

Fall back BRIGHTDATA_API_KEY -> BRIGHTDATA_API_TOKEN -> API_TOKEN, precedence
preserved, empty strings ignored. Update the no-key error message to match,
add resolve_api_key coverage, and harden the add-mcp test to clear all three
vars so it stays hermetic regardless of the caller's environment.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant