diff --git a/oauth2_http/java/com/google/auth/http/HttpCredentialsAdapter.java b/oauth2_http/java/com/google/auth/http/HttpCredentialsAdapter.java
index a66547a29..858de50ca 100644
--- a/oauth2_http/java/com/google/auth/http/HttpCredentialsAdapter.java
+++ b/oauth2_http/java/com/google/auth/http/HttpCredentialsAdapter.java
@@ -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}
*
diff --git a/oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java b/oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java
index 73d9b01ee..723cec837 100644
--- a/oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java
+++ b/oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java
@@ -31,7 +31,9 @@
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;
@@ -39,6 +41,7 @@
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));
+ }
}
diff --git a/oauth2_http/pom.xml b/oauth2_http/pom.xml
index 77e7e9736..5eda08b18 100644
--- a/oauth2_http/pom.xml
+++ b/oauth2_http/pom.xml
@@ -141,5 +141,11 @@
junit
test
+
+ org.hamcrest
+ hamcrest-core
+ 1.3
+ test
+