Skip to content

feat(auth): add ForceBasicAuth to override Bearer challenges - #1182

Open
TerryHowe wants to merge 1 commit into
oras-project:mainfrom
TerryHowe:feat/auth-force-basic
Open

feat(auth): add ForceBasicAuth to override Bearer challenges#1182
TerryHowe wants to merge 1 commit into
oras-project:mainfrom
TerryHowe:feat/auth-force-basic

Conversation

@TerryHowe

Copy link
Copy Markdown
Member

Summary

Part 3 of 3 splitting #1141 into reviewable chunks.

Add a ForceBasicAuth bool field to auth.Client. When true, a Bearer challenge from the registry is rewritten to a Basic challenge before credential handling. Useful for registries that advertise Bearer but also accept HTTP Basic for the same credential pair.

Implementation

Three lines in Client.Do(), right after parseChallenge() and before the existing scheme switch:

```go
if c.ForceBasicAuth && scheme == SchemeBearer {
scheme = SchemeBasic
}
```

The rest of the basic-auth path runs unchanged. The override bypasses the bearer flow entirely, so it does not interact with the token-fetching logic.

Independence

Independent of PRs A (#1180) and B (#1181). Based directly on `main`. Can land in any order relative to the other two.

Test plan

  • `go test -mod=mod ./registry/remote/auth/...` — passes
  • New `TestClient_Do_ForceBasicAuth_OverridesBearer` verifies: registry sends Bearer challenge → client retries with Basic header → 200
  • CI on this PR

Replaces #1141 together with PRs A and B.

@codecov

codecov Bot commented May 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.13%. Comparing base (3d90c80) to head (e0e0275).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1182      +/-   ##
==========================================
+ Coverage   83.06%   83.13%   +0.07%     
==========================================
  Files          82       82              
  Lines        5756     5758       +2     
==========================================
+ Hits         4781     4787       +6     
+ Misses        602      599       -3     
+ Partials      373      372       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@TerryHowe TerryHowe added this to the v3.0.0 milestone May 24, 2026
Add a ForceBasicAuth bool field to auth.Client. When true, a Bearer
challenge from the registry is rewritten to a Basic challenge before
credential handling. This is useful for registries that advertise Bearer
auth but also accept HTTP Basic for the same credential pair.

Implementation is a three-line scheme rewrite in Client.Do(), applied
right after parseChallenge() and before the scheme switch, so the rest
of the basic-auth path runs unchanged. The override bypasses bearer
flow entirely, so it does not interact with the token-fetching logic.

Refs oras-project#1141 (split: PR C of A/B/C). Independent of PRs A and B.

Signed-off-by: Terry Howe <terrylhowe@gmail.com>
@TerryHowe
TerryHowe force-pushed the feat/auth-force-basic branch from a8ba8de to e0e0275 Compare June 22, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

keep open v3 Things belongs to version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant