Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 7ddac43

Browse files
fix: follow up fix service account credentials createScopedRequired (#605)
1 parent 3d066ee commit 7ddac43

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public static ServiceAccountCredentials fromStream(
564564
/** Returns whether the scopes are empty, meaning createScoped must be called before use. */
565565
@Override
566566
public boolean createScopedRequired() {
567-
return scopes.isEmpty();
567+
return scopes.isEmpty() && defaultScopes.isEmpty();
568568
}
569569

570570
/**

oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,23 @@ public void createScopedRequired_emptyScopes() throws IOException {
488488
}
489489

490490
@Test
491-
public void createScopedRequired_nonEmptyScopes_false() throws IOException {
491+
public void createScopedRequired_nonEmptyScopes() throws IOException {
492492
GoogleCredentials credentials =
493493
ServiceAccountCredentials.fromPkcs8(
494494
CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, SCOPES);
495495

496496
assertFalse(credentials.createScopedRequired());
497497
}
498498

499+
@Test
500+
public void createScopedRequired_nonEmptyDefaultScopes() throws IOException {
501+
GoogleCredentials credentials =
502+
ServiceAccountCredentials.fromPkcs8(
503+
CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, null, SCOPES);
504+
505+
assertFalse(credentials.createScopedRequired());
506+
}
507+
499508
@Test
500509
public void fromJSON_getProjectId() throws IOException {
501510
MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();

0 commit comments

Comments
 (0)