List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets getDetails
public Details getDetails()
From source file:com.macquarie.analytics.CoreReportingApiReferenceSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(HelloAnalyticsApiSample.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out/*from w w w . j a v a2 s .co m*/ .println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=analytics " + "into analytics-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1); } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)) .setDataStoreFactory(DATA_STORE_FACTORY).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.macquarie.analytics.HelloAnalyticsApiSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(HelloAnalyticsApiSample.class.getResourceAsStream("client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out//from www . j a va 2 s . c om .println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=analytics " + "into analytics-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1); } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)) .setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.nokia.scbe.bestdayever.calendar.CalendarSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, CalendarSample.class.getResourceAsStream("/client_secrets.json")); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar " + "into calendar-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);/*from w w w .j a v a 2 s . c o m*/ } // set up file credential store FileCredentialStore credentialStore = new FileCredentialStore( new File(System.getProperty("user.home"), ".credentials/calendar.json"), JSON_FACTORY); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setCredentialStore(credentialStore) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.randstad.googlecalendarsync.Utils.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ public static Credential authorize(List<String> scopes) throws Exception { // Load client secrets. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(SyncTokenSample.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter")) { System.out.println(//from www . ja v a 2 s. co m "Overwrite the src/main/resources/client_secrets.json file with the client secrets file " + "you downloaded from your Google Developers Console project."); System.exit(1); } GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build(); // Authorize. return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.sappe.ontrack.security.CalendarSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(CalendarSample.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar " + "into calendar-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);// ww w . jav a 2 s . c om } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.tango.BucketSyncer.StorageClients.GCSClient.java
License:Apache License
private Credential gcsAuthorize() throws IOException, IllegalArgumentException { //load the file FileInputStream inputStream = null; try {//from ww w. j av a 2 s. c o m File gcs_config = new File("config/gcscfg.json"); inputStream = new FileInputStream(gcs_config); } catch (Exception e) { log.error("Failed to find the config file for gcs client: ", e); throw new IllegalArgumentException("Failed to find the config file for gcs client"); } GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(GCS_JSON_FACTORY, new InputStreamReader(inputStream)); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { log.info("Enter CLIENT ID and Secret from https://code.google.com/apis/console/?api=storage_api " + "into config/gcscfg.json"); throw new IllegalArgumentException("Please provide credentials in config/gcscfg.json"); } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(gcsHttpTransport, GCS_JSON_FACTORY, clientSecrets, Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)) .setDataStoreFactory(gcsDataStoreFactory).build(); //check id and key are provided if (flow.getClientId() == null) { log.error("Please provide valid GCS credentials"); throw new IllegalArgumentException("Please provide valid GCS credentials"); } // gcsAuthorize log.warn( "GCS opens the browser / provides the url to verify the account. If you find a 401 error returned from the browser, it means that the client_id is invalid. Please abort this application. Provide a valid client_id and try again"); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.tfgridiron.crowdsource.cmdline.GameCharter.java
License:Apache License
private static void authorize() throws Exception { httpTransport = GoogleNetHttpTransport.newTrustedTransport(); dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // load client secrets InputStream inputStream = GameCharter.class.getResourceAsStream("/client_secrets.json"); if (inputStream == null) { inputStream = GameCharter.class.getResourceAsStream("client_secrets.json"); if (inputStream == null) { inputStream = GameCharter.class.getResourceAsStream("resources/client_secrets.json"); if (inputStream == null) { inputStream = GameCharter.class.getResourceAsStream("/resources/client_secrets.json"); }/*from ww w . ja va 2s. c om*/ } } if (inputStream == null) { throw new IOException("Could not get client_secrets.json from ... anywhere"); } GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(inputStream)); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.err.println("Internal erorr: Enter Client ID and Secret from " + "https://code.google.com/apis/console/?api=drive into client_secrets.json"); System.exit(1); } Set<String> scopes = new HashSet<String>(2); scopes.add(DriveScopes.DRIVE); scopes.add(Constants.OAUTH_SPREADSHEET_SCOPE); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build(); // authorize credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.wut.datasource.GoogleAnalyticsDataSource.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(AnalyticsSample.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out/*from w w w . java 2 s . c o m*/ .println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=analytics " + "into analytics-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1); } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY)) .setDataStoreFactory(DATA_STORE_FACTORY).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.yagasoft.overcast.implement.google.Authorisation.java
License:MIT License
/** * @see com.yagasoft.overcast.base.csp.authorisation.OAuth#acquirePermission() *///from ww w.j a va 2s. co m @Override public void acquirePermission() throws AuthorisationException { Logger.info("GOOGLE: AUTH: started ..."); // authorise try { // the folder where Google API stores creds. dataStoreFolder = tokenParent; dataStoreFactory = new FileDataStoreFactory(dataStoreFolder.toFile()); // load the JSON containing info required for identifying the dev account. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(Google.JSON_FACTORY, new InputStreamReader(Files.newInputStream(infoFile))); // dev info contained in the JSON. String clientId = clientSecrets.getDetails().getClientId(); String clientSecret = clientSecrets.getDetails().getClientSecret(); // problem?! if (clientId.startsWith("Enter") || clientSecret.startsWith("Enter")) { Logger.error( "GOOGLE: AUTH: Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive " + "into google_secrets.json"); throw new AuthorisationException("Failed to authorise!"); } // set up authorisation code flow flow = new GoogleAuthorizationCodeFlow.Builder(Google.httpTransport, Google.JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE)) .setCredentialDataStore(getDataStore(dataStoreFactory, "google")) .setAccessType("offline").build(); credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(userID); Logger.info("Google: AUTH: success"); } catch (IOException e) { Logger.error("Google: AUTH: failed"); Logger.except(e); e.printStackTrace(); throw new AuthorisationException("Failed to authorise! " + e.getMessage()); } }
From source file:controllers.PlusSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader("C:\\first_play\\app\\installed.json")); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println("Enter Client ID and Secret from https://code.google.com/apis/console/?api=plus " + "into plus-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);// w w w .jav a2 s . c om } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }