Skip to content

Commit

Permalink
try using ExternalAccountCredentials instead of GoogleCredentials
Browse files Browse the repository at this point in the history
spotless
  • Loading branch information
snf2ye committed Oct 21, 2024
1 parent 7823074 commit 4e15e49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bio.terra.app.configuration;

import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.ExternalAccountCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -20,7 +21,7 @@ public record ResourceBufferServiceConfiguration(
public String getAccessToken() throws IOException {
try (FileInputStream fileInputStream = new FileInputStream(clientCredentialFilePath)) {
GoogleCredentials credentials =
GoogleCredentials.fromStream(fileInputStream).createScoped(BUFFER_SCOPES);
ExternalAccountCredentials.fromStream(fileInputStream).createScoped(BUFFER_SCOPES);
AccessToken token = credentials.refreshAccessToken();
return token.getTokenValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.api.gax.rpc.ApiException;
import com.google.api.resourcenames.ResourceName;
import com.google.auth.oauth2.AccessToken;
import com.google.auth.oauth2.ExternalAccountCredentials;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.billing.v1.BillingAccountName;
import com.google.cloud.billing.v1.CloudBillingClient;
Expand Down Expand Up @@ -42,7 +43,8 @@ private static CloudBillingClient accessClient(AuthenticatedUserRequest user) {
if (user == null || user.getToken().isEmpty()) {
// Authentication is provided by the 'gcloud' tool when running locally
// and by built-in service accounts when running on GAE, GCE, or GKE.
GoogleCredentials serviceAccountCredentials = GoogleCredentials.getApplicationDefault();
GoogleCredentials serviceAccountCredentials =
ExternalAccountCredentials.getApplicationDefault();

// The createScopedRequired method returns true when running on GAE or a local developer
// machine. In that case, the desired scopes must be passed in manually. When the code is
Expand Down

0 comments on commit 4e15e49

Please sign in to comment.