/** Returns the authentication credentials. If required, credentials are scoped. */ public Credentials getScopedCredentials() { Credentials credentialsToReturn = credentials; if (credentials instanceof GoogleCredentials && ((GoogleCredentials) credentials).createScopedRequired()) { credentialsToReturn = ((GoogleCredentials) credentials).createScoped(getScopes()); } return credentialsToReturn; }
return scopes.isEmpty() ? credentials : credentials.createScoped(scopes);
public ContainerRegistryAuthSupplier build() { final GoogleCredentials credentials = this.credentials.createScoped(scopes); // log some sort of identifier for the credentials, which requires looking at the // instance type if (credentials instanceof ServiceAccountCredentials) { final String clientEmail = ((ServiceAccountCredentials) credentials).getClientEmail(); log.info("loaded credentials for service account with clientEmail={}", clientEmail); } else if (credentials instanceof UserCredentials) { final String clientId = ((UserCredentials) credentials).getClientId(); log.info("loaded credentials for user account with clientId={}", clientId); } final Clock clock = Clock.systemDefaultZone(); final DefaultCredentialRefresher refresher = new DefaultCredentialRefresher(); return new ContainerRegistryAuthSupplier(credentials, clock, minimumExpiryMillis, refresher); } }
/** Returns the authentication credentials. If required, credentials are scoped. */ public Credentials getScopedCredentials() { Credentials credentialsToReturn = credentials; if (credentials instanceof GoogleCredentials && ((GoogleCredentials) credentials).createScopedRequired()) { credentialsToReturn = ((GoogleCredentials) credentials).createScoped(getScopes()); } return credentialsToReturn; }
private synchronized Storage getService() throws IOException, GeneralSecurityException { logger.trace("Getting Google Cloud Storage service"); // leave this here for tests because they do things like manipulate properties dynamically to test invalid values this.bucketName = properties.getProperty( "usergrid.binary.bucketname" ); if (instance == null) { // Google provides different authentication types which are different based on if the application is // running within GCE(Google Compute Engine) or GAE (Google App Engine). If Usergrid is running in // GCE or GAE, the SDK will automatically authenticate and get access to // cloud storage. Else, the full path to a credential file should be provided in the following environment variable // // GOOGLE_APPLICATION_CREDENTIALS // // The SDK will attempt to load the credential file for a service account. See the following // for more info: https://developers.google.com/identity/protocols/application-default-credentials#howtheywork GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(StorageScopes.all()); final TransportOptions transportOptions = HttpTransportOptions.newBuilder() .setConnectTimeout(30000) // in milliseconds .setReadTimeout(30000) // in milliseconds .build(); instance = StorageOptions.newBuilder() .setCredentials(credentials) .setTransportOptions(transportOptions) .build() .getService(); } return instance; }
@BeforeClass public static void beforeClass() throws IOException { Credentials credentials = GoogleCredentials.getApplicationDefault() .createScoped(DiskTypeSettings.getDefaultServiceScopes()); diskTypeSettings = DiskTypeSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(credentials)) .build(); diskTypeClient = DiskTypeClient.create(diskTypeSettings); }
private static ServiceAccountCredentials getCredentials() throws Exception { GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(IAM_SCOPE)); // service account credentials are required to sign the jwt token if (credentials == null || !(credentials instanceof ServiceAccountCredentials)) { throw new Exception("Google credentials : service accounts credentials expected"); } return (ServiceAccountCredentials) credentials; }
static void authExplicit(String jsonPath) throws IOException { // You can specify a credential file by providing a path to GoogleCredentials. // Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS environment variable. GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath)) .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform")); Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService(); System.out.println("Buckets:"); Page<Bucket> buckets = storage.list(); for (Bucket bucket : buckets.iterateAll()) { System.out.println(bucket.toString()); } } // [END auth_cloud_explicit]
/** * If the credentials support scopes, creates a copy of the the identity with the specified * scopes; otherwise, returns the same instance. * * @param scopes Collection of scopes to request. * @return GoogleCredentials with requested scopes. */ public GoogleCredentials createScoped(String... scopes) { return createScoped(scopes); }
/** * If the credentials support scopes, creates a copy of the the identity with the specified * scopes; otherwise, returns the same instance. * * @param scopes Collection of scopes to request. * @return GoogleCredentials with requested scopes. */ public GoogleCredentials createScoped(String... scopes) { return createScoped(scopes); }
@Override public Credentials getCredentials() throws IOException { if (this.credentials == null) { return GoogleCredentials.getApplicationDefault().createScoped(this.CPS_SCOPE); } else { return this.credentials.createScoped(this.CPS_SCOPE); } }
@Bean @ConditionalOnMissingBean(Credentials.class) Credentials googleCredentials() throws IOException { return GoogleCredentials.getApplicationDefault() .createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append")); }
/** Returns a default GCP {@link Credentials} or null when it fails. */ @Override public Credentials getCredential() { try { return GoogleCredentials.getApplicationDefault().createScoped(SCOPES); } catch (IOException e) { // Ignore the exception // Pipelines that only access to public data should be able to run without credentials. return null; } } }
@Bean @ConditionalOnMissingBean(Credentials.class) Credentials googleCredentials() throws IOException { return GoogleCredentials.getApplicationDefault() .createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append")); }
@Provides @Singleton final Credentials provideCredentials(HttpTransportFactory transport, @Scopes List<String> scopes) throws IOException { return GoogleCredentials.getApplicationDefault(checkNotNull(transport)).createScoped(scopes); } }
@Override public Credentials getCredential() throws IOException, GeneralSecurityException { return GoogleCredentials.fromStream(new FileInputStream(options.getServiceAccountFile())).createScoped(SCOPES); } }
@Override public Credentials getCredential() throws IOException, GeneralSecurityException { return GoogleCredentials.fromStream(new FileInputStream(options.getServiceAccountFile())).createScoped(SCOPES); } }
@Provides @Singleton Credentials provideCredentials(@ClientSecretsFile String clientSecretsFile, @Scopes List<String> scopes) throws FileNotFoundException, IOException { return GoogleCredentials .fromStream(new FileInputStream(clientSecretsFile)) .createScoped(scopes); } }
public static Credentials createCredentials(BigQueryDatastoreProperties datastore) { try { GoogleCredentials credential = GoogleCredentials .fromStream(new FileInputStream(datastore.serviceAccountFile.getValue())).createScoped(BigqueryScopes.all()); return credential; } catch (IOException e) { throw new RuntimeException("Exception when read service account file: " + datastore.serviceAccountFile.getValue() + "\nMessage is:" + e.getMessage()); } }
public static Credentials createCredentials(BigQueryDatastoreProperties datastore) { try { GoogleCredentials credential = GoogleCredentials .fromStream(new FileInputStream(datastore.serviceAccountFile.getValue())).createScoped(BigqueryScopes.all()); return credential; } catch (IOException e) { throw new RuntimeException("Exception when read service account file: " + datastore.serviceAccountFile.getValue() + "\nMessage is:" + e.getMessage()); } }