use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project camel by apache.
the class BatchGoogleCalendarClientFactory method authorizeServiceAccount.
private Credential authorizeServiceAccount(String emailAddress, String p12FileName, Collection<String> scopes, String user) throws Exception {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
// set the service account user when provided
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory).setServiceAccountId(emailAddress).setServiceAccountPrivateKeyFromP12File(new File(p12FileName)).setServiceAccountScopes(scopes).setServiceAccountUser(user).build();
return credential;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project camel by apache.
the class GooglePubsubConnectionFactory method createDefault.
private GoogleCredential createDefault() throws Exception {
GoogleCredential credential = GoogleCredential.getApplicationDefault();
Collection pubSubScopes = Collections.singletonList(PubsubScopes.PUBSUB);
if (credential.createScopedRequired()) {
credential = credential.createScoped(pubSubScopes);
}
return credential;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project zeppelin by apache.
the class BigQueryInterpreter method createAuthorizedClient.
//Function that Creates an authorized client to Google Bigquery.
private static Bigquery createAuthorizedClient() throws IOException {
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory);
if (credential.createScopedRequired()) {
Collection<String> bigqueryScopes = BigqueryScopes.all();
credential = credential.createScoped(bigqueryScopes);
}
return new Bigquery.Builder(transport, jsonFactory, credential).setApplicationName("Zeppelin/1.0 (GPN:Apache Zeppelin;)").build();
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project beam by apache.
the class InjectorUtils method getClient.
/**
* Builds a new Pubsub client and returns it.
*/
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException {
checkNotNull(httpTransport);
checkNotNull(jsonFactory);
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(PubsubScopes.all());
}
if (credential.getClientAuthentication() != null) {
System.out.println("\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials.");
System.exit(1);
}
HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
return new Pubsub.Builder(httpTransport, jsonFactory, initializer).setApplicationName(APP_NAME).build();
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleCredential in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class InjectorUtils method getClient.
/**
* Builds a new Pubsub client and returns it.
*/
public static Pubsub getClient(final HttpTransport httpTransport, final JsonFactory jsonFactory) throws IOException {
checkNotNull(httpTransport);
checkNotNull(jsonFactory);
GoogleCredential credential = GoogleCredential.getApplicationDefault(httpTransport, jsonFactory);
if (credential.createScopedRequired()) {
credential = credential.createScoped(PubsubScopes.all());
}
if (credential.getClientAuthentication() != null) {
System.out.println("\n***Warning! You are not using service account credentials to " + "authenticate.\nYou need to use service account credentials for this example," + "\nsince user-level credentials do not have enough pubsub quota,\nand so you will run " + "out of PubSub quota very quickly.\nSee " + "https://developers.google.com/identity/protocols/application-default-credentials.");
System.exit(1);
}
HttpRequestInitializer initializer = new RetryHttpInitializerWrapper(credential);
return new Pubsub.Builder(httpTransport, jsonFactory, initializer).setApplicationName(APP_NAME).build();
}
Aggregations