-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to getApplicationDefault()-based auth. Modify docs+others acco…
…rdingly.
- Loading branch information
Showing
5 changed files
with
140 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; | ||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; | ||
import com.google.api.client.http.HttpTransport; | ||
import com.google.api.client.json.JsonFactory; | ||
import com.google.api.client.json.jackson2.JacksonFactory; | ||
import com.google.api.services.storage.Storage; | ||
import com.google.api.services.storage.StorageScopes; | ||
|
||
import java.io.IOException; | ||
import java.security.GeneralSecurityException; | ||
import java.util.Collection; | ||
|
||
/* | ||
* Copyright (c) 2016 Google Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. You may obtain a | ||
* copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
|
||
/** | ||
* This class manages the details of creating a Storage service, including auth. | ||
*/ | ||
public class StorageFactory { | ||
|
||
private static Storage instance = null; | ||
|
||
public static synchronized Storage getService() throws IOException, GeneralSecurityException { | ||
if (instance == null) { | ||
instance = buildService(); | ||
} | ||
return instance; | ||
} | ||
|
||
private static Storage buildService() throws IOException, GeneralSecurityException { | ||
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); | ||
JsonFactory jsonFactory = new JacksonFactory(); | ||
GoogleCredential credential = GoogleCredential.getApplicationDefault(transport, jsonFactory); | ||
|
||
if (credential.createScopedRequired()) { | ||
Collection<String> bigqueryScopes = StorageScopes.all(); | ||
credential = credential.createScoped(bigqueryScopes); | ||
} | ||
|
||
return new Storage.Builder(transport, jsonFactory, credential) | ||
.setApplicationName("GCS Samples") | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This broke the Java sample here:
https://cloud.google.com/docs/authentication
Can you revert this change or fix the auth page?