Skip to content

feat(security): an oauth2 scheme is a bearer at runtime - #3

Merged
zdunecki merged 1 commit into
masterfrom
feat/oauth2-bearer
Nov 10, 2026
Merged

zdunecki merged 1 commit into
masterfrom
feat/oauth2-bearer

Conversation

@zdunecki

Copy link
Copy Markdown
Member

An OpenAPI security scheme of type: oauth2 is, at runtime, a bearer token (RFC 6750: the access token travels as Authorization: Bearer <token>), so both converters now map it to the bearer kind:

  • openapi2opensdk: oauth2 → kind: "bearer", scheme: "bearer", the scheme's name and env var kept; two optional IR fields record the flow types (flows) and the merged scope catalogue (scopes), left out when empty — other schemes serialize exactly as before (no golden moved). The IR schema declares both.
  • openapi2opencli: oauth2 → kind: "bearer".
  • Every generated runtime branches on kind, so the output for an oauth2 document is byte-identical to the same document with an http/bearer scheme (a behaviour test generates all nine targets both ways and compares). For the Go and Java SDKs and both CLI generators this is also a fix: they sent no credential at all for an unrecognised scheme.
  • opensdk diff: a document-level move from http/bearer to oauth2 is not a security-changed (tested; openIdConnect still is). A per-operation move to a scoped requirement is still reported, by design — a client lacking the scope breaks.

Gates: cargo fmt --check, clippy --workspace --all-targets -D warnings, cargo test --workspace 527 passed, scripts/check-standalone.sh OK. README gains an Authentication section; CHANGELOG has the Unreleased entry.

An OAuth 2.0 access token is sent as `Authorization: Bearer <token>`
(RFC 6750), so at runtime an `oauth2` security scheme is a bearer
credential. Both converters mapped it to `other`, which the Go and Java
SDKs and both CLI generators treat as "send nothing".

- openapi2opensdk: `oauth2` -> `kind: "bearer"`, `scheme: "bearer"`, plus
  `flows` (the flow types, document order, `x-*` keys skipped) and
  `scopes` (the scope catalogue merged across flows, first description
  wins). Both are optional and appended last, so every existing IR keeps
  its bytes; they are declared on `SdkSecurity` in the IR schema.
- openapi2opencli: `oauth2` -> `kind: "bearer"`, `scheme: "bearer"`.
- Generated SDKs and CLIs for an oauth2 document are byte-identical to the
  http/bearer ones (same env var, same header), pinned for all nine
  targets in the CLI behavior suite.
- `opensdk diff` no longer reports an http/bearer -> oauth2 document as
  `security-changed`; an unmapped scheme still is.
- README: an Authentication section; CHANGELOG: Unreleased entry.
@zdunecki
zdunecki merged commit ecaf619 into master Nov 10, 2026
3 checks passed
@zdunecki
zdunecki deleted the feat/oauth2-bearer branch November 15, 2026 02:36
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