List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets getDetails
public Details getDetails()
From source file:GoogleDriveAPI.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(GoogleDriveAPI.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=drive " + "into drive-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);/*from www . j av a2s. c o m*/ } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE)).setDataStoreFactory(dataStoreFactory) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:DriveSample.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(DriveSample.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=drive " + "into drive-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);//w w w . j av a 2s. c o m } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE)).setDataStoreFactory(dataStoreFactory) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:PlusSample.java
License:Apache License
private static Credential authorize() throws Exception { GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(PlusSample.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=plus " + "into plus-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);/* w w w .j a v a 2 s. c om*/ } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(PlusScopes.PLUS_ME)).setDataStoreFactory(dataStoreFactory) .build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:calendariotaller.CalendarSample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets Reader lector = new InputStreamReader( CalendarSample.class.getResourceAsStream("/calendariotaller/client_secrets.json")); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, lector); 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 ww w . j av a 2 s .co m*/ } // 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:calendar_cmdline_sample.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);//from ww w. ja v a 2 s . com } // 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("125417063487-6o5o98l9oqbbj5sor3ru2b1aq1ih214i.apps.googleusercontent.com"); }
From source file:com.aalmeida.lightning.external.auth.GoogleAuthorizationImpl.java
License:Apache License
/** * Authorize./* w w w . ja v a 2 s .c o m*/ * * @param pUrl * the url * @return the credential * @throws Exception * the exception */ private static Credential authorize(String pUrl) throws Exception { URL url = new URL(pUrl); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, in); String clientId = clientSecrets.getDetails().getClientId(); String clientSecret = clientSecrets.getDetails().getClientSecret(); if ((clientId == null) || (clientId.isEmpty()) || (clientSecret == null) || (clientSecret.isEmpty())) { throw new Exception("Empty Google credencials"); } GoogleClientSecrets.Details details = new GoogleClientSecrets.Details(); details.setClientId(clientId); details.setClientSecret(clientSecret); clientSecrets.setInstalled(details); List<String> permissions = new ArrayList<String>(); permissions.add("https://www.googleapis.com/auth/calendar"); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, permissions).setAccessType("offline").setApprovalPrompt("force") .setDataStoreFactory(dataStoreFactory).build(); return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.abubusoft.liferay.google.GoogleOAuth.java
License:Open Source License
protected GoogleAuthorizationCodeFlow getFlow(long companyId) throws Exception { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); InputStream is = GoogleOAuth.class.getResourceAsStream(_CLIENT_SECRETS_LOCATION); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(is)); //clientSecrets.getDetails(). String apiKey = PrefsPropsUtil.getString(companyId, "google.api.key"); String apiSecret = PrefsPropsUtil.getString(companyId, "google.api.secret"); String apiCallbackURL = PrefsPropsUtil.getString(companyId, "google.api.callback.url"); if (apiKey != null && apiKey.trim().length() > 0) { clientSecrets.getDetails().setClientId(apiKey); }//from w w w . j av a 2s. c o m if (apiSecret != null && apiSecret.trim().length() > 0) { clientSecrets.getDetails().setClientSecret(apiSecret); } if (apiCallbackURL != null && apiCallbackURL.trim().length() > 0) { clientSecrets.getDetails().getRedirectUris().add(apiCallbackURL); } GoogleAuthorizationCodeFlow.Builder builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, _SCOPES); builder.setAccessType("online"); builder.setApprovalPrompt("force"); return builder.build(); }
From source file:com.blitz.picasaclient.CredentialsProvider.java
License:Apache License
/** * Authorizes the installed application to access user's protected data. * <p>//from www.j a v a 2 s . c o m * <p>If you plan to run on AppEngine or Compute Engine, consider instead * {@link GoogleCredential#getApplicationDefault()}, which will use the ambient credentials * for the project's service-account. */ public static Credential authorize(HttpTransport httpTransport, JsonFactory jsonFactory, Stage stage) throws IOException, GeneralSecurityException { dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR); // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(CredentialsProvider.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://console.developers.google.com/project/_/apiui/" + "credential into storage-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1); } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, Arrays.asList("https://picasaweb.google.com/data/", PlusScopes.PLUS_ME, PlusScopes.USERINFO_EMAIL)) .setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationHelper(flow).authorize(clientSecrets.getDetails().getClientId(), stage); }
From source file:com.compguide.web.google.calendar.api.GoogleCalendar.java
public static Credential refreshToken(User user, Credential oldCredential) throws IOException { InputStream in = GoogleCalendar.class.getResourceAsStream("/client_id.json"); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); TokenResponse response = new GoogleRefreshTokenRequest(HTTP_TRANSPORT, JSON_FACTORY, oldCredential.getRefreshToken(), clientSecrets.getDetails().getClientId(), clientSecrets.getDetails().getClientSecret()).execute(); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = authorizationCodeFlow("online"); //Now, with the token and user id, we have credentials Credential credential = flow.createAndStoreCredential(response, user.getIduser().toString()); return credential; }
From source file:com.dnalog.fmrp.google.GoogleClientCredentials.java
License:Apache License
public static Credential authorize(GoogleClientSecrets clientSecrets, List scopes) throws Exception { String authorizationCode = ""; String authorizeUrl = new GoogleAuthorizationCodeRequestUrl(clientSecrets, (clientSecrets.getDetails().getRedirectUris().get(0)), scopes).setState("").build(); System.out.println("Paste this URL into a web browser to authorize BigQuery Access:\n" + authorizeUrl); System.out.println("... and type the code you received here: "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); authorizationCode = in.readLine();/*w w w . ja va2s. c om*/ GoogleAuthorizationCodeFlow flow = getFlow(clientSecrets, scopes); GoogleTokenResponse response = flow.newTokenRequest(authorizationCode) .setRedirectUri(clientSecrets.getDetails().getRedirectUris().get(0)).execute(); System.out.println("Token response: " + response); return flow.createAndStoreCredential(response, null); }