Skip to content

Commit f17cd91

Browse files
committed
Addressed PR comments.
1 parent 6215db5 commit f17cd91

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

samples/snippets/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@
7575
<version>2.20.27</version>
7676
</dependency>
7777

78-
<!-- Gson -->
79-
<dependency>
80-
<groupId>com.google.code.gson</groupId>
81-
<artifactId>gson</artifactId>
82-
<version>2.10.1</version>
83-
</dependency>
8478

8579
<!-- Test dependencies-->
8680
<dependency>

samples/snippets/src/main/java/CustomCredentialSupplierAwsWorkload.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import com.google.auth.oauth2.AwsCredentials;
18-
import com.google.auth.oauth2.AwsSecurityCredentialsSupplier;
19-
import com.google.auth.oauth2.ExternalAccountSupplierContext;
20-
import com.google.auth.oauth2.GoogleCredentials;
17+
import com.google.auth.oauth2.*;
2118
import com.google.cloud.storage.Bucket;
2219
import com.google.cloud.storage.Storage;
2320
import com.google.cloud.storage.StorageOptions;
@@ -34,7 +31,7 @@
3431
public class CustomCredentialSupplierAwsWorkload {
3532

3633
public static void main(String[] args) {
37-
// TODO(Developer): Replace these variables with your actual values.
34+
// TODO(Developer): Set these environment variable values.
3835
String gcpWorkloadAudience = System.getenv("GCP_WORKLOAD_AUDIENCE");
3936
String saImpersonationUrl = System.getenv("GCP_SERVICE_ACCOUNT_IMPERSONATION_URL");
4037
String gcsBucketName = System.getenv("GCS_BUCKET_NAME");
@@ -115,7 +112,7 @@ public String getRegion(ExternalAccountSupplierContext context) {
115112

116113
/** Retrieves AWS security credentials using the AWS SDK's default provider chain. */
117114
@Override
118-
public com.google.auth.oauth2.AwsSecurityCredentials getCredentials(
115+
public AwsSecurityCredentials getCredentials(
119116
ExternalAccountSupplierContext context) {
120117
software.amazon.awssdk.auth.credentials.AwsCredentials credentials =
121118
this.awsCredentialsProvider.resolveCredentials();

samples/snippets/src/main/java/CustomCredentialSupplierOktaWorkload.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* limitations under the License.
1515
*/
1616

17+
import com.google.api.client.json.GenericJson;
18+
import com.google.api.client.json.gson.GsonFactory;
1719
import com.google.auth.oauth2.ExternalAccountSupplierContext;
1820
import com.google.auth.oauth2.GoogleCredentials;
1921
import com.google.auth.oauth2.IdentityPoolCredentials;
2022
import com.google.auth.oauth2.IdentityPoolSubjectTokenSupplier;
2123
import com.google.cloud.storage.Bucket;
2224
import com.google.cloud.storage.Storage;
2325
import com.google.cloud.storage.StorageOptions;
24-
import com.google.gson.Gson;
25-
import com.google.gson.JsonObject;
2626
import java.io.BufferedReader;
2727
import java.io.DataOutputStream;
2828
import java.io.IOException;
@@ -188,13 +188,16 @@ private void fetchOktaAccessToken() throws IOException {
188188
response.append(line);
189189
}
190190

191-
Gson gson = new Gson();
192-
JsonObject jsonObject = gson.fromJson(response.toString(), JsonObject.class);
191+
GenericJson jsonObject =
192+
GsonFactory.getDefaultInstance()
193+
.createJsonParser(response.toString())
194+
.parse(GenericJson.class);
193195

194-
if (jsonObject.has("access_token") && jsonObject.has("expires_in")) {
195-
this.accessToken = jsonObject.get("access_token").getAsString();
196-
int expiresIn = jsonObject.get("expires_in").getAsInt();
197-
this.expiryTime = System.currentTimeMillis() + expiresIn * 1000;
196+
if (jsonObject.containsKey("access_token") && jsonObject.containsKey("expires_in")) {
197+
this.accessToken = (String) jsonObject.get("access_token");
198+
Number expiresInNumber = (Number) jsonObject.get("expires_in");
199+
int expiresIn = expiresInNumber.intValue();
200+
this.expiryTime = System.currentTimeMillis() + expiresIn * 1000L;
198201
System.out.println(
199202
"[Supplier] Successfully received Access Token from Okta. Expires in "
200203
+ expiresIn

0 commit comments

Comments
 (0)