Skip to content

Commit 91dba11

Browse files
committed
Support transport and binding-enforcement MDS parameters.
1 parent 2761a39 commit 91dba11

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ public class ComputeEngineCredentials extends GoogleCredentials
122122

123123
private final Collection<String> scopes;
124124

125+
private final String transport;
126+
private final String bindingEnforcement;
127+
125128
private transient HttpTransportFactory transportFactory;
126129
private transient String serviceAccountEmail;
127130

@@ -152,6 +155,8 @@ private ComputeEngineCredentials(ComputeEngineCredentials.Builder builder) {
152155
scopeList.removeAll(Arrays.asList("", null));
153156
this.scopes = ImmutableSet.<String>copyOf(scopeList);
154157
}
158+
this.transport = builder.getTransport();
159+
this.bindingEnforcement = builder.getBindingEnforcement();
155160
}
156161

157162
@Override
@@ -191,7 +196,10 @@ public final Collection<String> getScopes() {
191196
}
192197

193198
/**
194-
* If scopes is specified, add "?scopes=comma-separated-list-of-scopes" to the token url.
199+
* If scopes is specified, add "?scopes=comma-separated-list-of-scopes" to the token url. If
200+
* transport is specified, add "?transport=xyz" to the token url; xyz is one of "alts" or "mtls".
201+
* If bindingEnforcement is specified, add "?binding-enforcement=xyz" to the token url; xyz is one
202+
* of "iam-policy" or "on".
195203
*
196204
* @return token url with the given scopes
197205
*/
@@ -200,6 +208,12 @@ String createTokenUrlWithScopes() {
200208
if (!scopes.isEmpty()) {
201209
tokenUrl.set("scopes", Joiner.on(',').join(scopes));
202210
}
211+
if (!transport.isEmpty()) {
212+
tokenUrl.set("transport", transport);
213+
}
214+
if (!bindingEnforcement.isEmpty()) {
215+
tokenUrl.set("binding-enforcement", bindingEnforcement);
216+
}
203217
return tokenUrl.toString();
204218
}
205219

@@ -643,6 +657,9 @@ public static class Builder extends GoogleCredentials.Builder {
643657
private Collection<String> scopes;
644658
private Collection<String> defaultScopes;
645659

660+
private String transport = "";
661+
private String bindingEnforcement = "";
662+
646663
protected Builder() {
647664
setRefreshMargin(COMPUTE_REFRESH_MARGIN);
648665
setExpirationMargin(COMPUTE_EXPIRATION_MARGIN);
@@ -684,6 +701,18 @@ public Builder setQuotaProjectId(String quotaProjectId) {
684701
return this;
685702
}
686703

704+
@CanIgnoreReturnValue
705+
public Builder setTransport(String transport) {
706+
this.transport = transport;
707+
return this;
708+
}
709+
710+
@CanIgnoreReturnValue
711+
public Builder setBindingEnforcement(String bindingEnforcement) {
712+
this.bindingEnforcement = bindingEnforcement;
713+
return this;
714+
}
715+
687716
public HttpTransportFactory getHttpTransportFactory() {
688717
return transportFactory;
689718
}
@@ -696,6 +725,14 @@ public Collection<String> getDefaultScopes() {
696725
return defaultScopes;
697726
}
698727

728+
public String getTransport() {
729+
return transport;
730+
}
731+
732+
public String getBindingEnforcement() {
733+
return bindingEnforcement;
734+
}
735+
699736
@Override
700737
public ComputeEngineCredentials build() {
701738
return new ComputeEngineCredentials(this);

0 commit comments

Comments
 (0)