Skip to content

Commit 06bf21a

Browse files
authored
feat: adds external account authorized user credentials (#1129)
* feat: adds external account authorized user credentials * fix: positioning * fix: serialVersionUID * fix: toString() test * fix: tests
1 parent 326e4a1 commit 06bf21a

File tree

8 files changed

+1756
-28
lines changed

8 files changed

+1756
-28
lines changed

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

Lines changed: 513 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ public static GoogleCredentials fromStream(
181181
if (ExternalAccountCredentials.EXTERNAL_ACCOUNT_FILE_TYPE.equals(fileType)) {
182182
return ExternalAccountCredentials.fromJson(fileContents, transportFactory);
183183
}
184+
if (ExternalAccountAuthorizedUserCredentials.EXTERNAL_ACCOUNT_AUTHORIZED_USER_FILE_TYPE.equals(
185+
fileType)) {
186+
return ExternalAccountAuthorizedUserCredentials.fromJson(fileContents, transportFactory);
187+
}
184188
if ("impersonated_service_account".equals(fileType)) {
185189
return ImpersonatedCredentials.fromJson(fileContents, transportFactory);
186190
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
import static com.google.common.base.Preconditions.checkNotNull;
3535

36+
import com.google.api.client.http.HttpResponseException;
37+
import com.google.api.client.json.GenericJson;
38+
import com.google.api.client.json.JsonParser;
39+
import java.io.IOException;
3640
import javax.annotation.Nullable;
3741

3842
/**
@@ -77,4 +81,21 @@ String getErrorDescription() {
7781
String getErrorUri() {
7882
return errorUri;
7983
}
84+
85+
static OAuthException createFromHttpResponseException(HttpResponseException e)
86+
throws IOException {
87+
JsonParser parser = OAuth2Utils.JSON_FACTORY.createJsonParser((e).getContent());
88+
GenericJson errorResponse = parser.parseAndClose(GenericJson.class);
89+
90+
String errorCode = (String) errorResponse.get("error");
91+
String errorDescription = null;
92+
String errorUri = null;
93+
if (errorResponse.containsKey("error_description")) {
94+
errorDescription = (String) errorResponse.get("error_description");
95+
}
96+
if (errorResponse.containsKey("error_uri")) {
97+
errorUri = (String) errorResponse.get("error_uri");
98+
}
99+
return new OAuthException(errorCode, errorDescription, errorUri);
100+
}
80101
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,7 @@ public StsTokenExchangeResponse exchangeToken() throws IOException {
107107
GenericData responseData = response.parseAs(GenericData.class);
108108
return buildResponse(responseData);
109109
} catch (HttpResponseException e) {
110-
GenericJson errorResponse = parseJson((e).getContent());
111-
String errorCode = (String) errorResponse.get("error");
112-
String errorDescription = null;
113-
String errorUri = null;
114-
if (errorResponse.containsKey("error_description")) {
115-
errorDescription = (String) errorResponse.get("error_description");
116-
}
117-
if (errorResponse.containsKey("error_uri")) {
118-
errorUri = (String) errorResponse.get("error_uri");
119-
}
120-
throw new OAuthException(errorCode, errorDescription, errorUri);
110+
throw OAuthException.createFromHttpResponseException(e);
121111
}
122112
}
123113

0 commit comments

Comments
 (0)