Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds external account authorized user credentials #1129

Merged
merged 6 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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