Search in sources :

Example 1 with GoogleCredential

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;
}
Also used : NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) HttpTransport(com.google.api.client.http.HttpTransport) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) File(java.io.File)

Example 2 with GoogleCredential

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;
}
Also used : Collection(java.util.Collection) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Example 3 with GoogleCredential

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();
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) InterpreterPropertyBuilder(org.apache.zeppelin.interpreter.InterpreterPropertyBuilder) JsonFactory(com.google.api.client.json.JsonFactory) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory)

Example 4 with GoogleCredential

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();
}
Also used : GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Example 5 with GoogleCredential

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();
}
Also used : GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Aggregations

GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)14 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)5 HttpTransport (com.google.api.client.http.HttpTransport)5 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)5 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)3 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)3 IOException (java.io.IOException)3 JsonFactory (com.google.api.client.json.JsonFactory)2 File (com.google.api.services.drive.model.File)2 Storage (com.google.api.services.storage.Storage)2 File (java.io.File)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Credential (com.google.api.client.auth.oauth2.Credential)1 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)1 HttpRequest (com.google.api.client.http.HttpRequest)1 Compute (com.google.api.services.compute.Compute)1 Fusiontables (com.google.api.services.fusiontables.Fusiontables)1 Pubsub (com.google.api.services.pubsub.Pubsub)1 Bucket (com.google.api.services.storage.model.Bucket)1 Provides (com.google.inject.Provides)1