|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
| 17 | +import com.google.api.client.json.GenericJson; |
| 18 | +import com.google.api.client.json.gson.GsonFactory; |
17 | 19 | import com.google.auth.oauth2.ExternalAccountSupplierContext; |
18 | 20 | import com.google.auth.oauth2.GoogleCredentials; |
19 | 21 | import com.google.auth.oauth2.IdentityPoolCredentials; |
20 | 22 | import com.google.auth.oauth2.IdentityPoolSubjectTokenSupplier; |
21 | 23 | import com.google.cloud.storage.Bucket; |
22 | 24 | import com.google.cloud.storage.Storage; |
23 | 25 | import com.google.cloud.storage.StorageOptions; |
24 | | -import com.google.gson.Gson; |
25 | | -import com.google.gson.JsonObject; |
26 | 26 | import java.io.BufferedReader; |
27 | 27 | import java.io.DataOutputStream; |
28 | 28 | import java.io.IOException; |
@@ -188,13 +188,16 @@ private void fetchOktaAccessToken() throws IOException { |
188 | 188 | response.append(line); |
189 | 189 | } |
190 | 190 |
|
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); |
193 | 195 |
|
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; |
198 | 201 | System.out.println( |
199 | 202 | "[Supplier] Successfully received Access Token from Okta. Expires in " |
200 | 203 | + expiresIn |
|
0 commit comments