2929/**
3030 * This class manages the details of creating a Storage service, including auth.
3131 */
32+ // [START authentication_application_default_credentials]
3233public class StorageFactory {
33-
3434 private static Storage instance = null ;
3535
3636 public static synchronized Storage getService () throws IOException , GeneralSecurityException {
@@ -45,13 +45,18 @@ private static Storage buildService() throws IOException, GeneralSecurityExcepti
4545 JsonFactory jsonFactory = new JacksonFactory ();
4646 GoogleCredential credential = GoogleCredential .getApplicationDefault (transport , jsonFactory );
4747
48+ // Depending on the environment that provides the default credentials (for
49+ // example: Compute Engine, App Engine), the credentials may require us to
50+ // specify the scopes we need explicitly. Check for this case, and inject
51+ // the Cloud Storage scope if required.
4852 if (credential .createScopedRequired ()) {
49- Collection <String > bigqueryScopes = StorageScopes .all ();
50- credential = credential .createScoped (bigqueryScopes );
53+ Collection <String > scopes = StorageScopes .all ();
54+ credential = credential .createScoped (scopes );
5155 }
5256
5357 return new Storage .Builder (transport , jsonFactory , credential )
5458 .setApplicationName ("GCS Samples" )
5559 .build ();
5660 }
5761}
62+ // [END authentication_application_default_credentials]
0 commit comments