Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for access_token as alias to token in registry authentication response. #420

Merged
merged 3 commits into from
Jun 19, 2018
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.concurrent.ExecutionException;
import javax.annotation.Nullable;

// TODO: This is probably not necessary anymore either.
/**
* Authenticates push to a target registry using Docker Token Authentication.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ private static RegistryAuthenticationFailedException newRegistryAuthenticationFa
private static class AuthenticationResponseTemplate implements JsonTemplate {

@Nullable private String token;

/**
* {@code access_token} is accepted as an alias for {@code token}.
*
* @see <a
* href="https://docs.docker.com/registry/spec/auth/token/#token-response-fields">https://docs.docker.com/registry/spec/auth/token/#token-response-fields</a>
*/
@Nullable private String access_token;

/** @return {@link #token} if not null, or {@link #access_token} */
@Nullable
private String getToken() {
if (token != null) {
return token;
}
return access_token;
}
}

private final String authenticationUrlBase;
Expand Down Expand Up @@ -164,11 +181,11 @@ private Authorization authenticate(String scope) throws RegistryAuthenticationFa

AuthenticationResponseTemplate responseJson =
JsonTemplateMapper.readJson(responseString, AuthenticationResponseTemplate.class);
if (responseJson.token == null) {
if (responseJson.getToken() == null) {
throw new RegistryAuthenticationFailedException(
"Did not get token in authentication response from " + authenticationUrl);
}
return Authorizations.withBearerToken(responseJson.token);
return Authorizations.withBearerToken(responseJson.getToken());
}

} catch (IOException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ RegistryCredentials retrieve(@Nullable String registry) {
return null;
}

// TODO: Add log message that says using credentials from Maven settings.
return new RegistryCredentials(
CREDENTIAL_SOURCE,
Authorizations.withBasicCredentials(
Expand Down