From ea19a8b08ff7841137ef4f758507309ce2f1b3a6 Mon Sep 17 00:00:00 2001 From: arithmetic1728 Date: Thu, 18 Mar 2021 13:14:34 -0700 Subject: [PATCH 1/2] fix: fix service account credentials createScopedRequired --- .../com/google/auth/oauth2/ServiceAccountCredentials.java | 6 ++++++ .../google/auth/oauth2/ServiceAccountCredentialsTest.java | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java index aa9043611..741a4b27d 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -561,6 +561,12 @@ public static ServiceAccountCredentials fromStream( fileType, SERVICE_ACCOUNT_FILE_TYPE)); } + /** Returns whether the scopes are empty, meaning createScoped must be called before use. */ + @Override + public boolean createScopedRequired() { + return scopes.isEmpty(); + } + /** * Refreshes the OAuth2 access token by getting a new access token using a JSON Web Token (JWT). */ diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java index 904093154..3122da51e 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java @@ -479,12 +479,12 @@ public void createdScoped_defaultScopes() throws IOException { } @Test - public void createScopedRequired_emptyScopes_false() throws IOException { + public void createScopedRequired_emptyScopes_true() throws IOException { GoogleCredentials credentials = ServiceAccountCredentials.fromPkcs8( CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, EMPTY_SCOPES); - assertFalse(credentials.createScopedRequired()); + assertTrue(credentials.createScopedRequired()); } @Test From 8a23d96bb37161aada3d606e18826e07c5e54cdd Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Thu, 18 Mar 2021 13:52:18 -0700 Subject: [PATCH 2/2] Update oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java --- .../com/google/auth/oauth2/ServiceAccountCredentialsTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java index 3122da51e..604f68c60 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ServiceAccountCredentialsTest.java @@ -479,7 +479,7 @@ public void createdScoped_defaultScopes() throws IOException { } @Test - public void createScopedRequired_emptyScopes_true() throws IOException { + public void createScopedRequired_emptyScopes() throws IOException { GoogleCredentials credentials = ServiceAccountCredentials.fromPkcs8( CLIENT_ID, CLIENT_EMAIL, PRIVATE_KEY_PKCS8, PRIVATE_KEY_ID, EMPTY_SCOPES);