Skip to content

Normalize egress auth-required for broker-backed OAuth #589

Closed

Description

@dcramer

PR #588 made plugin auth detection signal-only (egress proxy is authoritative, no bash text heuristics). This follow-up aligns the broker-backed credential path with the plugin-hook path and fills the unhandled upstream-rejection case.

Background

Two credential-needed paths currently exist in the egress layer:

Plugin hook path (e.g. GitHub):

issueCredential hook → { type: "needed", authorization: {...} }
  → SandboxEgressCredentialNeededError (self-describing, carries auth context)
  → proxy writes auth_required signal

Broker path (all simple oauth-bearer plugins, e.g. Sentry):

oauth-bearer-broker → throws CredentialUnavailableError
  → proxy catches raw error, separately calls getPluginOAuthConfig()
  → proxy reconstructs authorization context, writes auth_required signal

The broker is already the shared OAuth implementation for simple providers — it handles token lookup, scope checking, refresh, and lease issuance. Simple plugins should not need their own issueCredential hook. The gap is that the broker path doesn't produce a self-describing egress error; the proxy has to look up authorization context separately.

Scope

Part 1 — Normalize credential-needed at the egress boundary

Convert broker-backed CredentialUnavailableError into SandboxEgressCredentialNeededError in egress-credentials.ts, before it reaches the proxy. Both paths should converge on one canonical error type so the proxy handles a single credential-needed contract:

egress-credentials.ts:
  broker throws CredentialUnavailableError
    → convert to SandboxEgressCredentialNeededError with provider, grant, authorization
  (same as plugin hook path already does)

proxy:
  one handler for SandboxEgressCredentialNeededError → auth_required signal

The proxy's separate CredentialUnavailableError reconstruction path goes away.

Part 2 — Handle upstream auth rejection for broker-injected bearer credentials

Currently unhandled:

broker finds token → proxy injects bearer → upstream returns 401
→ no auth_required signal emitted → no re-auth triggered

Add core egress response classification for broker-backed OAuth bearer leases. When an authenticated request is rejected upstream with an auth-invalid response, core should emit the same auth_required signal. This should be shared infrastructure, not per-plugin OAuth logic.

Non-goals

  • Simple OAuth-bearer plugins must not need to implement their own token storage, refresh, or issuance hooks
  • No bash/stdout auth heuristics (removed in fix(auth): Normalize credential auth handoff #588)
  • No changes to OAuth pause UX or Redis signal transport
  • GitHub multi-grant credential behavior is unchanged

Acceptance criteria

  • Broker missing-token and scope-gap cases produce the same canonical SandboxEgressCredentialNeededError as plugin hook providers, with authorization context embedded
  • Proxy no longer reconstructs authorization context from CredentialUnavailableError for the broker path
  • When a broker-injected bearer token is rejected by the upstream (401), an auth_required signal is emitted without per-plugin OAuth code in the plugin package
  • Tests cover: broker no-token, broker scope-gap, plugin-hook needed, broker upstream-401-after-injection
  • PR fix(auth): Normalize credential auth handoff #588 behavior is preserved: auth orchestration uses structured signal only

Refs #588.

Activity

  1. added a commit that references this issue on Jun 10, 2026
    ad5296f
  2. added a commit that references this issue on Jun 12, 2026
    e5b1d4c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions