com.google.auth.Credentials

Here are the examples of the java api class com.google.auth.Credentials taken from open source projects.

1. AppEngineCredentialsTest#constructor_usesAppIdentityService()

View license
@Test
public void constructor_usesAppIdentityService() throws IOException {
    final String expectedAccessToken = "ExpectedAccessToken";
    MockAppIdentityService appIdentity = new MockAppIdentityService();
    appIdentity.setAccessTokenText(expectedAccessToken);
    Credentials credentials = new AppEngineCredentials(SCOPES, appIdentity);
    Map<String, List<String>> metadata = credentials.getRequestMetadata(CALL_URI);
    assertEquals(1, appIdentity.getGetAccessTokenCallCount());
    assertContainsBearerToken(metadata, expectedAccessToken);
}

2. ServiceAccountJwtAccessCredentialsTest#getRequestMetadata_noURI_throws()

View license
@Test
public void getRequestMetadata_noURI_throws() throws IOException {
    PrivateKey privateKey = ServiceAccountCredentials.privateKeyFromPkcs8(SA_PRIVATE_KEY_PKCS8);
    Credentials credentials = new ServiceAccountJwtAccessCredentials(SA_CLIENT_ID, SA_CLIENT_EMAIL, privateKey, SA_PRIVATE_KEY_ID);
    try {
        credentials.getRequestMetadata();
        fail("exception expected");
    } catch (IOException e) {
    }
}

3. ServiceAccountJwtAccessCredentialsTest#getAuthenticationType_returnsJwtAccess()

View license
@Test
public void getAuthenticationType_returnsJwtAccess() throws IOException {
    Credentials credentials = ServiceAccountJwtAccessCredentials.fromPkcs8(SA_CLIENT_ID, SA_CLIENT_EMAIL, SA_PRIVATE_KEY_PKCS8, SA_PRIVATE_KEY_ID);
    assertEquals(credentials.getAuthenticationType(), "JWTAccess");
}

4. ServiceAccountJwtAccessCredentialsTest#hasRequestMetadata_returnsTrue()

View license
@Test
public void hasRequestMetadata_returnsTrue() throws IOException {
    Credentials credentials = ServiceAccountJwtAccessCredentials.fromPkcs8(SA_CLIENT_ID, SA_CLIENT_EMAIL, SA_PRIVATE_KEY_PKCS8, SA_PRIVATE_KEY_ID);
    assertTrue(credentials.hasRequestMetadata());
}

5. ServiceAccountJwtAccessCredentialsTest#hasRequestMetadataOnly_returnsTrue()

View license
@Test
public void hasRequestMetadataOnly_returnsTrue() throws IOException {
    Credentials credentials = ServiceAccountJwtAccessCredentials.fromPkcs8(SA_CLIENT_ID, SA_CLIENT_EMAIL, SA_PRIVATE_KEY_PKCS8, SA_PRIVATE_KEY_ID);
    assertTrue(credentials.hasRequestMetadataOnly());
}

6. ServiceAccountJwtAccessCredentialsTest#getRequestMetadata_hasJwtAccess()

View license
@Test
public void getRequestMetadata_hasJwtAccess() throws IOException {
    PrivateKey privateKey = ServiceAccountCredentials.privateKeyFromPkcs8(SA_PRIVATE_KEY_PKCS8);
    Credentials credentials = new ServiceAccountJwtAccessCredentials(SA_CLIENT_ID, SA_CLIENT_EMAIL, privateKey, SA_PRIVATE_KEY_ID);
    Map<String, List<String>> metadata = credentials.getRequestMetadata(CALL_URI);
    verifyJwtAccess(metadata, SA_CLIENT_EMAIL, CALL_URI, SA_PRIVATE_KEY_ID);
}

7. ServiceAccountJwtAccessCredentialsTest#getRequestMetadata_defaultURI_hasJwtAccess()

View license
@Test
public void getRequestMetadata_defaultURI_hasJwtAccess() throws IOException {
    PrivateKey privateKey = ServiceAccountCredentials.privateKeyFromPkcs8(SA_PRIVATE_KEY_PKCS8);
    Credentials credentials = new ServiceAccountJwtAccessCredentials(SA_CLIENT_ID, SA_CLIENT_EMAIL, privateKey, SA_PRIVATE_KEY_ID, CALL_URI);
    Map<String, List<String>> metadata = credentials.getRequestMetadata();
    verifyJwtAccess(metadata, SA_CLIENT_EMAIL, CALL_URI, SA_PRIVATE_KEY_ID);
}