Search in sources :

Example 16 with AccessToken

use of com.google.auth.oauth2.AccessToken in project google-auth-library-java by google.

the class ServiceAccountCredentialsTest method refreshAccessToken_tokenExpiry.

@Test
public void refreshAccessToken_tokenExpiry() throws IOException {
    final String tokenString = "1/MkSJoj1xsli0AccessToken_NKPY2";
    MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
    MockTokenServerTransport transport = transportFactory.transport;
    ServiceAccountCredentials credentials = ServiceAccountCredentials.fromPkcs8(SA_CLIENT_ID, SA_CLIENT_EMAIL, SA_PRIVATE_KEY_PKCS8, SA_PRIVATE_KEY_ID, SCOPES, transportFactory, null);
    credentials.clock = new FixedClock(0L);
    transport.addServiceAccount(SA_CLIENT_EMAIL, tokenString);
    AccessToken accessToken = credentials.refreshAccessToken();
    assertEquals(tokenString, accessToken.getTokenValue());
    assertEquals(3600 * 1000L, accessToken.getExpirationTimeMillis().longValue());
    // Test for large expires_in values (should not overflow).
    transport.setExpiresInSeconds(3600 * 1000);
    accessToken = credentials.refreshAccessToken();
    assertEquals(tokenString, accessToken.getTokenValue());
    assertEquals(3600 * 1000 * 1000L, accessToken.getExpirationTimeMillis().longValue());
}
Also used : MockTokenServerTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory) FixedClock(com.google.api.client.testing.http.FixedClock) Test(org.junit.Test)

Example 17 with AccessToken

use of com.google.auth.oauth2.AccessToken in project google-auth-library-java by google.

the class UserCredentialsTest method equals_false_accessToken.

@Test
public void equals_false_accessToken() throws IOException {
    final URI tokenServer1 = URI.create("https://foo1.com/bar");
    AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null);
    AccessToken otherAccessToken = new AccessToken("otherAccessToken", 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();
    UserCredentials otherCredentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).setRefreshToken(REFRESH_TOKEN).setAccessToken(otherAccessToken).setHttpTransportFactory(httpTransportFactory).setTokenServerUri(tokenServer1).build();
    assertFalse(credentials.equals(otherCredentials));
    assertFalse(otherCredentials.equals(credentials));
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) URI(java.net.URI) Test(org.junit.Test)

Example 18 with AccessToken

use of com.google.auth.oauth2.AccessToken in project google-auth-library-java by google.

the class UserCredentialsTest method equals_false_clientSecret.

@Test
public void equals_false_clientSecret() throws IOException {
    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();
    UserCredentials otherCredentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret("other client secret").setRefreshToken(REFRESH_TOKEN).setAccessToken(accessToken).setHttpTransportFactory(httpTransportFactory).setTokenServerUri(tokenServer1).build();
    assertFalse(credentials.equals(otherCredentials));
    assertFalse(otherCredentials.equals(credentials));
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) URI(java.net.URI) Test(org.junit.Test)

Example 19 with AccessToken

use of com.google.auth.oauth2.AccessToken in project google-auth-library-java by google.

the class UserCredentialsTest method hashCode_equals.

@Test
public void hashCode_equals() throws IOException {
    final URI tokenServer = URI.create("https://foo.com/bar");
    MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
    AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null);
    UserCredentials credentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).setRefreshToken(REFRESH_TOKEN).setAccessToken(accessToken).setHttpTransportFactory(transportFactory).setTokenServerUri(tokenServer).build();
    UserCredentials otherCredentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).setRefreshToken(REFRESH_TOKEN).setAccessToken(accessToken).setHttpTransportFactory(transportFactory).setTokenServerUri(tokenServer).build();
    assertEquals(credentials.hashCode(), otherCredentials.hashCode());
}
Also used : MockTokenServerTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory) URI(java.net.URI) Test(org.junit.Test)

Example 20 with AccessToken

use of com.google.auth.oauth2.AccessToken in project google-auth-library-java by google.

the class UserCredentialsTest method equals_false_refreshToken.

@Test
public void equals_false_refreshToken() throws IOException {
    final URI tokenServer1 = URI.create("https://foo1.com/bar");
    AccessToken accessToken = new AccessToken(ACCESS_TOKEN, null);
    MockHttpTransportFactory httpTransportFactory = new MockHttpTransportFactory();
    OAuth2Credentials credentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).setRefreshToken(REFRESH_TOKEN).setAccessToken(accessToken).setHttpTransportFactory(httpTransportFactory).setTokenServerUri(tokenServer1).build();
    OAuth2Credentials otherCredentials = UserCredentials.newBuilder().setClientId(CLIENT_ID).setClientSecret(CLIENT_SECRET).setRefreshToken("otherRefreshToken").setAccessToken(accessToken).setHttpTransportFactory(httpTransportFactory).setTokenServerUri(tokenServer1).build();
    assertFalse(credentials.equals(otherCredentials));
    assertFalse(otherCredentials.equals(credentials));
}
Also used : MockHttpTransportFactory(com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 AccessToken (com.google.auth.oauth2.AccessToken)17 URI (java.net.URI)14 AccessToken (io.vertx.ext.auth.oauth2.AccessToken)13 MockTokenServerTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockTokenServerTransportFactory)12 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)8 JsonObject (io.vertx.core.json.JsonObject)8 Date (java.util.Date)8 OAuth2TokenImpl (io.vertx.ext.auth.oauth2.impl.OAuth2TokenImpl)7 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)6 MockHttpTransportFactory (com.google.auth.oauth2.GoogleCredentialsTest.MockHttpTransportFactory)6 IOException (java.io.IOException)5 Client (javax.ws.rs.client.Client)5 AccessToken (org.glassfish.jersey.client.oauth1.AccessToken)5 ConsumerCredentials (org.glassfish.jersey.client.oauth1.ConsumerCredentials)5 Metadata (io.grpc.Metadata)4 Feature (javax.ws.rs.core.Feature)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 HttpRequest (com.google.api.client.http.HttpRequest)3 HttpRequestFactory (com.google.api.client.http.HttpRequestFactory)3