From 56c030e0eae1c37d15b6d58d94a13583e4d652fc Mon Sep 17 00:00:00 2001 From: Navina R Date: Wed, 9 Mar 2022 22:18:21 -0800 Subject: [PATCH 1/2] feat: Make it easy to convert a Pkcs8 encoded string to PrivateKey #883 This change adds a new method `setPrivateKeyString` in `ServiceAccountCredentials.Builder` to accept Pkcs8 encoded string representation of private keys. --- .../com/google/auth/oauth2/ServiceAccountCredentials.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java index 02aff547f..7b93ebf9c 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -1052,6 +1052,12 @@ public Builder setPrivateKey(PrivateKey privateKey) { return this; } + public Builder setPrivateKeyString(String privateKeyPkcs8) + throws IOException { + this.privateKey = privateKeyFromPkcs8(privateKeyPkcs8); + return this; + } + public Builder setPrivateKeyId(String privateKeyId) { this.privateKeyId = privateKeyId; return this; From ecc445561fd5dbadd6333dba574746b5d1d7be35 Mon Sep 17 00:00:00 2001 From: Timur Sadykov Date: Fri, 25 Mar 2022 15:30:32 -0700 Subject: [PATCH 2/2] lint fixes --- .../java/com/google/auth/oauth2/ServiceAccountCredentials.java | 3 +-- 1 file changed, 1 insertion(+), 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 7b93ebf9c..9b9c99c54 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ServiceAccountCredentials.java @@ -1052,8 +1052,7 @@ public Builder setPrivateKey(PrivateKey privateKey) { return this; } - public Builder setPrivateKeyString(String privateKeyPkcs8) - throws IOException { + public Builder setPrivateKeyString(String privateKeyPkcs8) throws IOException { this.privateKey = privateKeyFromPkcs8(privateKeyPkcs8); return this; }