Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ target/

# IDEs
.idea/
*.iml

# When testing JSON files
*.json
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/land/oras/auth/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,11 @@ private <T> ResponseWrapper<T> executeRequest(
LOG.debug("New scopes: {}", newScopes.getScopes());

// Add authentication header if any
if (authProvider.getAuthHeader(containerRef) != null
var authHeader = authProvider.getAuthHeader(containerRef);
if (authHeader != null
&& !authProvider.getAuthScheme().equals(AuthScheme.NONE)
&& includeAuthHeader) {
builder = builder.header(Const.AUTHORIZATION_HEADER, authProvider.getAuthHeader(containerRef));
builder = builder.header(Const.AUTHORIZATION_HEADER, authHeader);
}
headers.forEach(builder::header);

Expand Down Expand Up @@ -524,8 +525,16 @@ private <T> ResponseWrapper<T> redoRequest(
token.expires_in(),
token.issued_at().plusSeconds(token.expires_in()));
}
String bearerToken = token.token();
if (bearerToken == null) {
// Docker registry auth spec allows either token or auth_token (or both if they are the same)
bearerToken = token.access_token();
}
if (bearerToken == null) {
throw new OrasException("No Bearer token received");
}
try {
builder = builder.setHeader(Const.AUTHORIZATION_HEADER, "Bearer " + token.token());
builder = builder.setHeader(Const.AUTHORIZATION_HEADER, "Bearer " + bearerToken);
HttpResponse<T> newResponse = client.send(builder.build(), handler);

// Follow redirect
Expand Down
Loading