use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project dhis2-core by dhis2.
the class DefaultDhisConfigurationProvider method getGoogleAccessToken.
@Override
public Optional<GoogleAccessToken> getGoogleAccessToken() {
if (!getGoogleCredential().isPresent()) {
return Optional.empty();
}
GoogleCredential credential = getGoogleCredential().get();
try {
if (!credential.refreshToken() || credential.getExpiresInSeconds() == null) {
log.warn("There is no refresh token to be retrieved");
return Optional.empty();
}
} catch (IOException ex) {
throw new IllegalStateException("Could not retrieve refresh token: " + ex.getMessage(), ex);
}
GoogleAccessToken token = new GoogleAccessToken();
token.setAccessToken(credential.getAccessToken());
token.setClientId(getProperty(ConfigurationKey.GOOGLE_SERVICE_ACCOUNT_CLIENT_ID));
token.setExpiresInSeconds(credential.getExpiresInSeconds());
token.setExpiresOn(LocalDateTime.now().plusSeconds(token.getExpiresInSeconds()));
return Optional.of(token);
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project local-data-aragopedia by aragonopendata.
the class GoogleDriveAPI method authorize.
private static GoogleCredential authorize() throws IOException, GeneralSecurityException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(Prop.acountId).setServiceAccountScopes(SCOPES).setServiceAccountPrivateKeyFromP12File(new java.io.File(Prop.p12File)).build();
return credential;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project druid by druid-io.
the class GoogleStorageDruidModule method getGoogleStorage.
@Provides
@LazySingleton
public GoogleStorage getGoogleStorage(final GoogleAccountConfig config) throws IOException, GeneralSecurityException {
LOG.info("Building Cloud Storage Client...");
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(StorageScopes.all());
}
Storage storage = new Storage.Builder(httpTransport, jsonFactory, credential).setApplicationName(APPLICATION_NAME).build();
return new GoogleStorage(storage);
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project OpenRefine by OpenRefine.
the class FusionTableHandler method getFusionTablesService.
public static Fusiontables getFusionTablesService(String token) {
Credential credential = new GoogleCredential().setAccessToken(token);
Fusiontables fusiontables = new Fusiontables.Builder(GDataExtension.HTTP_TRANSPORT, GDataExtension.JSON_FACTORY, credential).setApplicationName(GDataExtension.SERVICE_APP_NAME).build();
;
return fusiontables;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project platformlayer by platformlayer.
the class GoogleComputeClientFactory method getComputeClient.
public GoogleComputeClient getComputeClient(GoogleCloud cloud) throws OpsException {
KeyParser parser = new KeyParser();
Object parsed = parser.parse(cloud.serviceAccountKey.plaintext());
PrivateKey privateKey;
if (parsed == null) {
throw new OpsException("Cannot parse private key");
} else if (parsed instanceof PrivateKey) {
privateKey = (PrivateKey) parsed;
} else {
throw new OpsException("Expected private key, found: " + parsed.getClass().getSimpleName());
}
// Build service account credential.
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT).setJsonFactory(JSON_FACTORY).setServiceAccountId(cloud.serviceAccountId).setServiceAccountScopes(ComputeScopes.COMPUTE).setServiceAccountPrivateKey(privateKey).build();
Compute compute = new Compute(HTTP_TRANSPORT, JSON_FACTORY, credential);
return new GoogleComputeClient(platformLayerClient, compute, cloud.projectId);
}
Aggregations