Skip to content

Commit c679ee7

Browse files
committed
Merge pull request #238 from GoogleCloudPlatform/swast-auth
Add missing Application Default Credentials region tags.
2 parents 56f8d0b + a5205cb commit c679ee7

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

storage/json-api/src/main/java/StorageFactory.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
/**
3030
* This class manages the details of creating a Storage service, including auth.
3131
*/
32+
// [START authentication_application_default_credentials]
3233
public 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

Comments
 (0)