Skip to content

Commit

Permalink
feat: adds external account authorized user credentials (#1129)
Browse files Browse the repository at this point in the history
* feat: adds external account authorized user credentials

* fix: positioning

* fix: serialVersionUID

* fix: toString() test

* fix: tests
  • Loading branch information
lsirac committed Jan 21, 2023
1 parent 326e4a1 commit 06bf21a
Show file tree
Hide file tree
Showing 8 changed files with 1,756 additions and 28 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public static GoogleCredentials fromStream(
if (ExternalAccountCredentials.EXTERNAL_ACCOUNT_FILE_TYPE.equals(fileType)) {
return ExternalAccountCredentials.fromJson(fileContents, transportFactory);
}
if (ExternalAccountAuthorizedUserCredentials.EXTERNAL_ACCOUNT_AUTHORIZED_USER_FILE_TYPE.equals(
fileType)) {
return ExternalAccountAuthorizedUserCredentials.fromJson(fileContents, transportFactory);
}
if ("impersonated_service_account".equals(fileType)) {
return ImpersonatedCredentials.fromJson(fileContents, transportFactory);
}
Expand Down
21 changes: 21 additions & 0 deletions oauth2_http/java/com/google/auth/oauth2/OAuthException.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

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

import com.google.api.client.http.HttpResponseException;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonParser;
import java.io.IOException;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -77,4 +81,21 @@ String getErrorDescription() {
String getErrorUri() {
return errorUri;
}

static OAuthException createFromHttpResponseException(HttpResponseException e)
throws IOException {
JsonParser parser = OAuth2Utils.JSON_FACTORY.createJsonParser((e).getContent());
GenericJson errorResponse = parser.parseAndClose(GenericJson.class);

String errorCode = (String) errorResponse.get("error");
String errorDescription = null;
String errorUri = null;
if (errorResponse.containsKey("error_description")) {
errorDescription = (String) errorResponse.get("error_description");
}
if (errorResponse.containsKey("error_uri")) {
errorUri = (String) errorResponse.get("error_uri");
}
return new OAuthException(errorCode, errorDescription, errorUri);
}
}
12 changes: 1 addition & 11 deletions oauth2_http/java/com/google/auth/oauth2/StsRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,7 @@ public StsTokenExchangeResponse exchangeToken() throws IOException {
GenericData responseData = response.parseAs(GenericData.class);
return buildResponse(responseData);
} catch (HttpResponseException e) {
GenericJson errorResponse = parseJson((e).getContent());
String errorCode = (String) errorResponse.get("error");
String errorDescription = null;
String errorUri = null;
if (errorResponse.containsKey("error_description")) {
errorDescription = (String) errorResponse.get("error_description");
}
if (errorResponse.containsKey("error_uri")) {
errorUri = (String) errorResponse.get("error_uri");
}
throw new OAuthException(errorCode, errorDescription, errorUri);
throw OAuthException.createFromHttpResponseException(e);
}
}

Expand Down
Loading

0 comments on commit 06bf21a

Please sign in to comment.