Skip to content
Permalink
Browse files
feat: added getter for credentials object in HttpCredentialsAdapter (#…
…658)

* feat: added getter for credentials object in HttpCredentialsAdapter

* add test for getCredentials

* fix imports and formatting
  • Loading branch information
shubha-rajan committed May 13, 2021
1 parent cc13ac6 commit 5a946ea5e0d974611f2205f468236db4b931e486
@@ -69,6 +69,11 @@ public HttpCredentialsAdapter(Credentials credentials) {
this.credentials = credentials;
}

/** A getter for the credentials instance being used */
public Credentials getCredentials() {
return credentials;
}

/**
* {@inheritDoc}
*
@@ -31,14 +31,17 @@

package com.google.auth.http;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.auth.Credentials;
import com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory;
import com.google.auth.oauth2.MockTokenCheckingTransport;
import com.google.auth.oauth2.OAuth2Credentials;
@@ -149,4 +152,25 @@ public void initialize_noURI() throws IOException {
String authorizationHeader = requestHeaders.getAuthorization();
assertEquals(authorizationHeader, expectedAuthorization);
}

@Test
public void getCredentials() {
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
MockTokenServerTransportFactory tokenServerTransportFactory =
new MockTokenServerTransportFactory();
tokenServerTransportFactory.transport.addClient(CLIENT_ID, CLIENT_SECRET);
tokenServerTransportFactory.transport.addRefreshToken(REFRESH_TOKEN, accessToken);

OAuth2Credentials credentials =
UserCredentials.newBuilder()
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setRefreshToken(REFRESH_TOKEN)
.setHttpTransportFactory(tokenServerTransportFactory)
.build();

HttpCredentialsAdapter adapter = new HttpCredentialsAdapter(credentials);
Credentials returnedCredentials = adapter.getCredentials();
assertThat(returnedCredentials, instanceOf(Credentials.class));
}
}
@@ -141,5 +141,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

0 comments on commit 5a946ea

Please sign in to comment.