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

Fix: Not loosing the access token when calling UserCredentials#ToBuil… #993

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ public static class Builder extends GoogleCredentials.Builder {
protected Builder() {}

protected Builder(UserCredentials credentials) {
super(credentials);
this.clientId = credentials.clientId;
this.clientSecret = credentials.clientSecret;
this.refreshToken = credentials.refreshToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,27 @@ public void IdTokenCredentials_NoUserEmailScope_throws() throws IOException {
}
}

@Test
public void toBuilder() throws IOException {
qcastel marked this conversation as resolved.
Show resolved Hide resolved
final URI tokenServer1 = URI.create("https://foo1.com/bar");
AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null);
MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory();
UserCredentials credentials =
UserCredentials.newBuilder()
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRefreshToken(REFRESH_TOKEN)
.setAccessToken(accessToken)
.setHttpTransportFactory(httpTransportFactory)
.setTokenServerUri(tokenServer1)
.build();

credentials.toBuilder().build();
qcastel marked this conversation as resolved.
Show resolved Hide resolved
UserCredentials otherCredentials = credentials.toBuilder().build();
assertEquals(credentials, otherCredentials);
}

qcastel marked this conversation as resolved.
Show resolved Hide resolved

static GenericJson writeUserJson(
String clientId, String clientSecret, String refreshToken, String quotaProjectId) {
GenericJson json = new GenericJson();
Expand Down