Skip to content
Open
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 @@ -224,6 +224,28 @@ String getAuthRequestParameters(
: serviceScope;
}

/**
* Same content as {@link #getAuthRequestParameters}, but with the OAuth2 refresh token
* redacted. Use this (never {@link #getAuthRequestParameters}) when building human-readable
* text such as exception messages or log output, since those routinely end up in build/CI
* logs -- the real, unredacted parameters must only ever be used for the actual HTTP request
* body sent to the registry's token endpoint.
*
* @param credential the credential used to authenticate
* @param repositoryScopes the repository scopes to authenticate for
* @return the auth request parameters, with any refresh token redacted
*/
@VisibleForTesting
String getRedactedAuthRequestParameters(
@Nullable Credential credential, Map<String, String> repositoryScopes) {
String parameters = getAuthRequestParameters(credential, repositoryScopes);
if (isOAuth2Auth(credential)) {
String password = Verify.verifyNotNull(credential).getPassword();
return parameters.replace("&refresh_token=" + password, "&refresh_token=<redacted>");
}
return parameters;
}
Comment thread
Dreamweaver156191 marked this conversation as resolved.

@VisibleForTesting
boolean isOAuth2Auth(@Nullable Credential credential) {
return credential != null && credential.isOAuth2RefreshToken();
Expand Down Expand Up @@ -292,7 +314,7 @@ private Authorization authenticate(
"Did not get token in authentication response from "
+ getAuthenticationUrl(credential, repositoryScopes)
+ "; parameters: "
+ getAuthRequestParameters(credential, repositoryScopes));
+ getRedactedAuthRequestParameters(credential, repositoryScopes));
}
return Authorization.fromBearerToken(responseJson.getToken());
}
Expand Down