Skip to content

feat: TEA 1.0.0 API key exchange at /token and discovery failover at /discovery - #42

Merged
vpetersson merged 2 commits into
sbomify:masterfrom
aurangzaib048:feat/tea-auth-discovery-failover
Nov 17, 2026
Merged

vpetersson merged 2 commits into
sbomify:masterfrom
aurangzaib048:feat/tea-auth-discovery-failover

Conversation

@aurangzaib048

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #34. These two commits were pushed to its branch after it was merged, so they never reached master. They close the remaining "shall" gaps against the TEA 1.0.0 discovery and auth rules.

  • TEA 1.0.0 auth baseline: on a 1.x server basic_auth is an API key. It goes only to POST /token (client_credentials over HTTP Basic, each part form-encoded first per RFC 6749 §2.3.1), and the access token is sent as the bearer token. auth/readme.md says a client "shall not" present an API key to a resource endpoint, which the client did until now. A token rejected with a 401 carrying an invalid_token challenge is replaced, and the request retried, once. Concurrent requests share one exchange. 0.4.0 servers keep plain Basic auth on every request.
  • Discovery failover at /discovery: TeaClient.from_tei(tei) returns (client, results). It tries the .well-known/tea endpoints in the order from_well_known would and uses /discovery as the probe. Connection errors, 5xx, a 404 that is not a TEA error, or an invalid body move to the next endpoint; a TEA error 404 (such as OBJECT_UNKNOWN), 401 or 403 ends discovery, as discovery/readme.md requires. from_well_known followed by discover could not fail over at that step. The CLI's discover, inspect and TEI download use it when no --base-url is given.
  • .well-known endpoint URLs: TeaEndpoint.url now uses the .well-known schema's own pattern, so a URL with userinfo, a query, a fragment or a trailing slash is rejected. Before, /v1.0.0 would be appended inside a query string, and requests turns userinfo into Basic auth that replaces the caller's credentials.

Behaviour changes

  • basic_auth against a 1.x server now calls POST /token first. A base URL without a /v<semver> suffix counts as 1.0.0, so code using basic_auth with a 0.4.0 server at such a URL needs spec_version="0.4.0" (noted in the README's Upgrading section).
  • The CLI's TEI commands without --base-url no longer send a HEAD probe before /discovery.

Changes by layer

Layer Changes
HTTP API key exchange at /token, one renewal on invalid_token, _read_json shared by get_json and the exchange
Client from_tei, from_well_known and from_tei share one candidate loop (_connect), api_key_exchange on 1.x
Models TeaEndpoint.url pattern from the .well-known schema
CLI _tei_session for discover, inspect and TEI download
Docs README (quick start, discovery, authentication, Upgrading), cli.md, FUTURE.md, CLAUDE.md

Test plan

  • 1197 tests passing, 95% branch coverage
  • New tests: key sent only to /token, form-encoding of the key parts, 0.4.0 Basic auth unchanged, one renewal and no second retry, OAuth error types, invalid token responses, one exchange under concurrency, failover on each listed failure, no failover on a TEA 404, 401 or 403, the URN form resolved only at 0.4.0 endpoints, endpoint URLs inside and outside the schema pattern
  • The URL pattern checked on the pydantic 2.1.0 floor
  • mypy, ruff check ., ruff format --check . clean
  • Not run against a live TEA 1.x server that requires authentication (none available)

…oints at /discovery

On a 1.x server basic_auth is an API key: it now goes only to POST /token (client_credentials,
each part form-encoded before Basic) and the access token is sent as the bearer token, replaced
once per request after a 401 invalid_token challenge. 0.4.0 servers keep plain Basic auth.

TeaClient.from_tei(tei) resolves a TEI through .well-known/tea and uses /discovery as the probe:
connection errors, 5xx, a non-TEA 404 or an invalid body move to the next endpoint, while a TEA
error 404, 401 or 403 ends discovery. The CLI's discover, inspect and TEI download use it.
Copilot AI balanced review requested due to automatic review settings November 10, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@vpetersson
vpetersson merged commit 926ca6a into sbomify:master Nov 17, 2026
6 checks passed
aurangzaib048 added a commit that referenced this pull request Nov 23, 2026
First libtea release on CalVer (ADR-0002): TEA 1.0.0 support with 0.4.0 server compatibility. v26.11.2 is an earlier tag on d395443 that was never released and lacks #42, so this release takes the next number.
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.

3 participants