Example usage for com.google.api.client.googleapis.auth.oauth2 GoogleCredential getServiceAccountPrivateKeyId

List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleCredential getServiceAccountPrivateKeyId

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.auth.oauth2 GoogleCredential getServiceAccountPrivateKeyId.

Prototype

@Beta
public final String getServiceAccountPrivateKeyId() 

Source Link

Document

Beta
Returns the ID of the private key to use with the service account flow or null if not using the service account flow.

Usage

From source file:org.silverpeas.core.admin.domain.driver.googledriver.GoogleDirectoryRequester.java

License:Open Source License

/**
 * Creates an authorized Credential object.
 * @param httpTransport the HTTP transport.
 * @return An authorized Credential object.
 * @throws IOException If the credentials.json file cannot be found.
 *//*from   w  ww  .j a v a  2 s  .  co  m*/
private Credential getServiceAccountCredentials(final HttpTransport httpTransport) throws IOException {
    final GoogleCredential credential;
    try (InputStream is = new FileInputStream(jsonKeyPath)) {
        credential = GoogleCredential.fromStream(is);
    }
    return new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(JSON_FACTORY)
            .setServiceAccountUser(serviceAccountUser).setServiceAccountId(credential.getServiceAccountId())
            .setServiceAccountScopes(SCOPES)
            .setServiceAccountPrivateKey(credential.getServiceAccountPrivateKey())
            .setServiceAccountPrivateKeyId(credential.getServiceAccountPrivateKeyId())
            .setTokenServerEncodedUrl(credential.getTokenServerEncodedUrl()).build();
}