Skip to content

feat(client): bearer and API-key authentication - #10

Open
gustavorps wants to merge 2 commits into
ParapluOU:mainfrom
gustavorps:pr/auth
Open

feat(client): bearer and API-key authentication#10
gustavorps wants to merge 2 commits into
ParapluOU:mainfrom
gustavorps:pr/auth

Conversation

@gustavorps

Copy link
Copy Markdown

Problem

The Rust client only supports Basic auth. The JavaScript client supports API keys and bearer tokens, and the TerminusDB cloud (DFRNT hub) authenticates with Personal Access Tokens (TERMINUSDB_ACCESS_TOKEN) — so Rust users cannot talk to managed deployments at all.

Design

Additive, no breaking change:

  • New AuthMethod enum: Basic { user, pass } | Bearer(String) | ApiKey(String)
  • AuthApply extension trait on RequestBuilder — every request path funnels through it; Basic/no override reproduces the historical .basic_auth() behavior exactly
  • Client methods with_bearer(token) / with_api_key(key) (client.rs)
  • The SSE/commit-stream connection (sse_manager.rs) carries the same override

The header forms are the ones the server accepts:

  • Bearer <token>
  • Apikey <key>

Tests

auth_tests.rs — unit-verified header construction for all three methods (default_client_uses_basic_auth, bearer_override_sets_authorization_header, api_key_override_sets_authorization_header). Green on cargo test -p terminusdb-client --lib.

Notes

  • Grounded in the DFRNT hub PAT flow — see docs/terminusdb/get-your-api-key.md
  • ~20 files touched, but mechanically (.basic_auth(...).apply_auth(self)); the collaboration Authorization-Remote header is intentionally untouched (separate concern, see PR fix(client): Authorization-Remote header casing #9)

Additive AuthMethod override (AuthApply extension trait): Basic remains
the default; with_bearer()/with_api_key() switch the Authorization header.
All request paths now funnel through apply_auth; the SSE manager carries
the same override for its connection.

Grounding: DFRNT hub Personal Access Tokens (TERMINUSDB_ACCESS_TOKEN).
Review vs terminusdb-client-js: formatAuthHeader maps apikey -> 'Token'
and the v12 docs (push-to-project.md) show 'Authorization(-Remote): Token
<PAT>'. The previous 'Apikey <key>' scheme would be rejected by the
server/cloud auth.
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