private static Credential authorizeWithServiceAccount( String serviceAccountEmail, File pk12File ) throws GeneralSecurityException, IOException { LOG.info( String.format( "Authorizing using Service Account: %s", serviceAccountEmail ) ); // Build service account credential. GoogleCredential credential = new GoogleCredential.Builder() .setTransport( httpTransport ) .setJsonFactory( JSON_FACTORY ) .setServiceAccountId( serviceAccountEmail ) .setServiceAccountScopes( Collections.singleton( AndroidPublisherScopes.ANDROIDPUBLISHER ) ) .setServiceAccountPrivateKeyFromP12File( pk12File == null ? new File( SRC_RESOURCES_KEY_P12 ) : pk12File ) .build(); return credential; }
.setJsonFactory(JSON_FACTORY) .setServiceAccountId(service_acct_email) .setServiceAccountScopes(scopes) .setServiceAccountPrivateKeyFromP12File(gcsPrivateKeyHandle) .build();
.setServiceAccountId(id.get()) .setServiceAccountPrivateKeyFromP12File(localCopied) .setServiceAccountScopes(serviceAccountScopes) .build(); } finally {
@VisibleForTesting protected YouTube createYouTubeClient() throws IOException, GeneralSecurityException { GoogleCredential.Builder credentialBuilder = new GoogleCredential.Builder() .setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(getConfig().getOauth().getServiceAccountEmailAddress()) .setServiceAccountScopes(scopes); if (StringUtils.isNotEmpty(getConfig().getOauth().getPathToP12KeyFile())) { File p12KeyFile = new File(getConfig().getOauth().getPathToP12KeyFile()); if (p12KeyFile.exists() && p12KeyFile.isFile() && p12KeyFile.canRead()) { credentialBuilder = credentialBuilder.setServiceAccountPrivateKeyFromP12File(p12KeyFile); } } Credential credential = credentialBuilder.build(); return new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("Streams Application").build(); }
private GoogleCredential createFromAccountKeyPair(HttpTransport httpTransport) { try { GoogleCredential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setServiceAccountId(serviceAccount) .setServiceAccountScopes(PubsubScopes.all()) .setServiceAccountPrivateKey(getPrivateKeyFromString(serviceAccountKey)) .build(); return credential; } catch (Exception e) { throw new RuntimeException(e); } }
private Credential authorize() throws Exception { Set<String> scopes = new HashSet<String>(); scopes.add(AnalyticsScopes.ANALYTICS); scopes.add(AnalyticsScopes.ANALYTICS_EDIT); scopes.add(AnalyticsScopes.ANALYTICS_MANAGE_USERS); scopes.add(AnalyticsScopes.ANALYTICS_PROVISION); scopes.add(AnalyticsScopes.ANALYTICS_READONLY); credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setServiceAccountId(emailAddress) .setServiceAccountScopes(scopes) .setServiceAccountPrivateKeyFromP12File(new File(certificateLocation)) .build(); return credential; }
private Analytics getAnalyticsService() throws GeneralSecurityException, IOException, RepositoryException { if (getPrivateKey() == null) { throw new IllegalArgumentException("Missing public/private key pair for Google Maps API"); } final GoogleCredential.Builder builder = new GoogleCredential.Builder() .setTransport(HTTP_TRANSPORT) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(getUserName()) .setServiceAccountScopes(Collections.singletonList(AnalyticsScopes.ANALYTICS_READONLY)); final PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), getPrivateKey(), "notasecret", "privatekey", "notasecret"); final GoogleCredential credential = builder.setServiceAccountPrivateKey(privateKey).build(); return new Analytics.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("hippocms7_reporting_v1").build(); }
private GoogleCredential createFromAccountKeyPair(HttpTransport httpTransport) { try { return new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(serviceAccount) .setServiceAccountScopes(BigqueryScopes.all()) .setServiceAccountPrivateKey(getPrivateKeyFromString(serviceAccountKey)) .build(); } catch (Exception e) { throw new RuntimeException(e); } }
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; } }
@VisibleForTesting protected Plus createPlusClient() throws IOException, GeneralSecurityException { credential = new GoogleCredential.Builder() .setJsonFactory(JSON_FACTORY) .setTransport(TRANSPORT) .setServiceAccountScopes(SCOPE) .setServiceAccountId(this.config.getOauth().getServiceAccountEmailAddress()) .setServiceAccountPrivateKeyFromP12File(new File(this.config.getOauth().getPathToP12KeyFile())) .build(); return new Plus.Builder(TRANSPORT,JSON_FACTORY, credential).setApplicationName(this.config.getOauth().getAppName()).build(); }
/** * {@link Beta} <br/> * For credentials that require scopes, creates a copy of the credential with the specified * scopes. */ @Beta public GoogleCredential createScoped(Collection<String> scopes) { if (serviceAccountPrivateKey == null) { return this; } return toBuilder() .setServiceAccountScopes(scopes) .build(); }
String account = properties.get("oauthAccount"); String clientId = properties.get("oauthClientId"); String secret = properties.get("oauthSecret"); File privateKey = getCertficateFile(); GoogleCredential.Builder builder = new GoogleCredential.Builder(); builder.setTransport(new NetHttpTransport()); builder.setServiceAccountId(account); builder.setJsonFactory(new GsonFactory()); builder.setClientSecrets(clientId, secret); builder.setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/bigquery")); builder.setServiceAccountPrivateKeyFromP12File(privateKey); GoogleCredential googleBigQueryCredential = builder.build(); Bigquery bigquery = new Bigquery.Builder(new NetHttpTransport(), new GsonFactory(), googleBigQueryCredential).setApplicationName("myAppName") .build();
private static GoogleCredential.Builder getCredentialBuilderWithoutPrivateKey( String serviceAccountId, Collection<String> serviceAccountScopes) throws GeneralSecurityException, IOException { HttpTransport transport = newTransport(); JsonFactory jsonFactory = newJsonFactory(); return new GoogleCredential.Builder() .setTransport(transport) .setJsonFactory(jsonFactory) .setServiceAccountId(serviceAccountId) .setServiceAccountScopes(serviceAccountScopes); }
private static GoogleCredential.Builder getCredentialBuilderWithoutPrivateKey( String serviceAccountId, Collection<String> serviceAccountScopes) throws GeneralSecurityException, IOException { HttpTransport transport = newTransport(); JsonFactory jsonFactory = newJsonFactory(); return new GoogleCredential.Builder() .setTransport(transport) .setJsonFactory(jsonFactory) .setServiceAccountId(serviceAccountId) .setServiceAccountScopes(serviceAccountScopes); }
private static GoogleCredential.Builder getCredentialBuilderWithoutPrivateKey( String serviceAccountId, Collection<String> serviceAccountScopes) throws GeneralSecurityException, IOException { HttpTransport transport = newTransport(); JsonFactory jsonFactory = newJsonFactory(); return new GoogleCredential.Builder() .setTransport(transport) .setJsonFactory(jsonFactory) .setServiceAccountId(serviceAccountId) .setServiceAccountScopes(serviceAccountScopes); }
private static GoogleCredential.Builder getCredentialBuilderWithoutPrivateKey( String account, Collection<String> scopes) throws GeneralSecurityException, IOException { NetHttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory jsonFactory = new JacksonFactory(); return new GoogleCredential.Builder() .setTransport(transport) .setJsonFactory(jsonFactory) .setServiceAccountId(account) .setServiceAccountScopes(scopes); }
.setJsonFactory(JSON_FACTORY) .setServiceAccountId(SERVICE_ACCOUNT_EMAIL) .setServiceAccountScopes(Collections.singleton(PlusScopes.PLUS_ME)) .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
/** Authorizes the installed application to access user's protected data. */ private static GoogleCredential authorize() throws Exception { return new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(JSON_FACTORY) .setServiceAccountId(SERVICE_ACCT_EMAIL) .setServiceAccountPrivateKeyFromP12File(new File( PredictionSample.class.getResource("/"+SERVICE_ACCT_KEYFILE).getFile())) .setServiceAccountScopes(Arrays.asList(PredictionScopes.PREDICTION, StorageScopes.DEVSTORAGE_READ_ONLY)) .build(); }
.setJsonFactory(JacksonFactory.getDefaultInstance()).setServiceAccountId(srvcAccountId) .setServiceAccountPrivateKeyFromP12File(new File(srvcAccountP12FilePath)) .setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)).build();
public GoogleAnalyticsApiFacade( HttpTransport httpTransport, JsonFactory jsonFactory, String application, String oathServiceEmail, File keyFile ) throws IOException, GeneralSecurityException { Assert.assertNotNull( httpTransport, "HttpTransport cannot be null" ); Assert.assertNotNull( jsonFactory, "JsonFactory cannot be null" ); Assert.assertNotBlank( application, "Application name cannot be empty" ); Assert.assertNotBlank( oathServiceEmail, "OAuth Service Email name cannot be empty" ); Assert.assertNotNull( keyFile, "OAuth secret key file cannot be null" ); this.httpTransport = httpTransport; Credential credential = new GoogleCredential.Builder() .setTransport( httpTransport ) .setJsonFactory( jsonFactory ) .setServiceAccountScopes( AnalyticsScopes.all() ) .setServiceAccountId( oathServiceEmail ) .setServiceAccountPrivateKeyFromP12File( keyFile ) .build(); analytics = new Analytics.Builder( httpTransport, jsonFactory, credential ) .setApplicationName( application ) .build(); }