Skip to content

Commit 608ee87

Browse files
authored
feat: adds universe_domain to external account creds (#1199)
1 parent 6c2be85 commit 608ee87

5 files changed

Lines changed: 178 additions & 34 deletions

File tree

‎oauth2_http/java/com/google/auth/oauth2/ExternalAccountCredentials.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ abstract static class CredentialSource implements java.io.Serializable {
9595
@Nullable private final String serviceAccountImpersonationUrl;
9696
@Nullable private final String clientId;
9797
@Nullable private final String clientSecret;
98+
@Nullable private final String universeDomain;
9899

99100
// This is used for Workforce Pools. It is passed to the Security Token Service during token
100101
// exchange in the `options` param and will be embedded in the token by the Security Token
@@ -214,6 +215,7 @@ protected ExternalAccountCredentials(
214215
this.environmentProvider =
215216
environmentProvider == null ? SystemEnvironmentProvider.getInstance() : environmentProvider;
216217
this.workforcePoolUserProject = null;
218+
this.universeDomain = null;
217219
this.serviceAccountImpersonationOptions =
218220
new ServiceAccountImpersonationOptions(new HashMap<String, Object>());
219221

@@ -265,6 +267,8 @@ protected ExternalAccountCredentials(ExternalAccountCredentials.Builder builder)
265267
"The workforce_pool_user_project parameter should only be provided for a Workforce Pool configuration.");
266268
}
267269

270+
this.universeDomain = builder.universeDomain;
271+
268272
validateTokenUrl(tokenUrl);
269273
if (serviceAccountImpersonationUrl != null) {
270274
validateServiceAccountImpersonationInfoUrl(serviceAccountImpersonationUrl);
@@ -403,6 +407,7 @@ static ExternalAccountCredentials fromJson(
403407
String clientSecret = (String) json.get("client_secret");
404408
String quotaProjectId = (String) json.get("quota_project_id");
405409
String userProject = (String) json.get("workforce_pool_user_project");
410+
String universeDomain = (String) json.get("universe_domain");
406411
Map<String, Object> impersonationOptionsMap =
407412
(Map<String, Object>) json.get("service_account_impersonation");
408413

@@ -423,6 +428,7 @@ static ExternalAccountCredentials fromJson(
423428
.setClientId(clientId)
424429
.setClientSecret(clientSecret)
425430
.setServiceAccountImpersonationOptions(impersonationOptionsMap)
431+
.setUniverseDomain(universeDomain)
426432
.build();
427433
} else if (isPluggableAuthCredential(credentialSourceMap)) {
428434
return PluggableAuthCredentials.newBuilder()
@@ -438,6 +444,7 @@ static ExternalAccountCredentials fromJson(
438444
.setClientSecret(clientSecret)
439445
.setWorkforcePoolUserProject(userProject)
440446
.setServiceAccountImpersonationOptions(impersonationOptionsMap)
447+
.setUniverseDomain(universeDomain)
441448
.build();
442449
}
443450
return IdentityPoolCredentials.newBuilder()
@@ -453,6 +460,7 @@ static ExternalAccountCredentials fromJson(
453460
.setClientSecret(clientSecret)
454461
.setWorkforcePoolUserProject(userProject)
455462
.setServiceAccountImpersonationOptions(impersonationOptionsMap)
463+
.setUniverseDomain(universeDomain)
456464
.build();
457465
}
458466

@@ -571,6 +579,11 @@ public String getWorkforcePoolUserProject() {
571579
return workforcePoolUserProject;
572580
}
573581

582+
@Nullable
583+
public String getUniverseDomain() {
584+
return universeDomain;
585+
}
586+
574587
@Nullable
575588
public ServiceAccountImpersonationOptions getServiceAccountImpersonationOptions() {
576589
return serviceAccountImpersonationOptions;
@@ -700,6 +713,7 @@ public abstract static class Builder extends GoogleCredentials.Builder {
700713
@Nullable protected Collection<String> scopes;
701714
@Nullable protected String workforcePoolUserProject;
702715
@Nullable protected ServiceAccountImpersonationOptions serviceAccountImpersonationOptions;
716+
@Nullable protected String universeDomain;
703717

704718
protected Builder() {}
705719

@@ -718,6 +732,7 @@ protected Builder(ExternalAccountCredentials credentials) {
718732
this.environmentProvider = credentials.environmentProvider;
719733
this.workforcePoolUserProject = credentials.workforcePoolUserProject;
720734
this.serviceAccountImpersonationOptions = credentials.serviceAccountImpersonationOptions;
735+
this.universeDomain = credentials.universeDomain;
721736
}
722737

723738
/**
@@ -870,6 +885,17 @@ public Builder setServiceAccountImpersonationOptions(Map<String, Object> options
870885
return this;
871886
}
872887

888+
/**
889+
* Sets the optional universe domain.
890+
*
891+
* @param universeDomain the universe domain to set
892+
* @return this {@code Builder} object
893+
*/
894+
public Builder setUniverseDomain(String universeDomain) {
895+
this.universeDomain = universeDomain;
896+
return this;
897+
}
898+
873899
/**
874900
* Sets the optional Environment Provider.
875901
*

‎oauth2_http/javatests/com/google/auth/oauth2/AwsCredentialsTest.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ public void createdScoped_clonedCredentialWithAddedScopes() {
746746
.setQuotaProjectId("quotaProjectId")
747747
.setClientId("clientId")
748748
.setClientSecret("clientSecret")
749+
.setUniverseDomain("universeDomain")
749750
.build();
750751

751752
List<String> newScopes = Arrays.asList("scope1", "scope2");
@@ -764,6 +765,8 @@ public void createdScoped_clonedCredentialWithAddedScopes() {
764765
assertEquals(credentials.getClientId(), newCredentials.getClientId());
765766
assertEquals(credentials.getClientSecret(), newCredentials.getClientSecret());
766767
assertEquals(newScopes, newCredentials.getScopes());
768+
assertEquals(credentials.getUniverseDomain(), newCredentials.getUniverseDomain());
769+
assertEquals("universeDomain", newCredentials.getUniverseDomain());
767770
}
768771

769772
@Test
@@ -991,6 +994,7 @@ public void serialize() throws IOException, ClassNotFoundException {
991994
.setQuotaProjectId("quotaProjectId")
992995
.setClientId("clientId")
993996
.setClientSecret("clientSecret")
997+
.setUniverseDomain("universeDomain")
994998
.setScopes(scopes)
995999
.build();
9961000

0 commit comments

Comments
 (0)
Sponsor
SponsoredKunjungi sekarang
Promo