List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets load
public static GoogleClientSecrets load(JsonFactory jsonFactory, Reader reader) throws IOException
From source file:com.kurento.demo.cpbrazil.youtube.Auth.java
License:Open Source License
public static Credential authorise(List<String> scopes, File credentialDataStore) throws IOException { FileCredentialStore credentialStore = new FileCredentialStore(credentialDataStore, JSON_FACTORY); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, Auth.class.getResourceAsStream("/client_secrets.json")); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialStore(credentialStore).build(); // TODO change this to remove the port LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(5555).build(); // Authorize. return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user"); }
From source file:com.lafargeholcim.planb.database.google.spreadsheets.GDataBase.java
/** * Creates an authorized Credential object. * @return an authorized Credential object. * @throws IOException//from w w w.j av a2 s.c o m */ public void authorize() throws IOException { // Load client secrets. InputStream in = GDataBase.class.getResourceAsStream("/secret/client_secret12.json"); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build(); Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) .authorize("user"); System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); CREDENTIAL = credential; }
From source file:com.liferay.google.GoogleOAuth.java
License:Open Source License
protected GoogleAuthorizationCodeFlow getFlow(long companyId) throws IOException, SystemException { HttpTransport httpTransport = new NetHttpTransport(); JacksonFactory jsonFactory = new JacksonFactory(); GoogleAuthorizationCodeFlow.Builder builder = null; String googleClientId = PrefsPropsUtil.getString(companyId, "google.client.id"); String googleClientSecret = PrefsPropsUtil.getString(companyId, "google.client.secret"); List<String> scopes = null; if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) { scopes = _SCOPES_DRIVE;//from www .j ava2 s . c o m } else { scopes = _SCOPES_LOGIN; } if (Validator.isNull(googleClientId) || Validator.isNull(googleClientSecret)) { InputStream is = GoogleOAuth.class.getResourceAsStream(_CLIENT_SECRETS_LOCATION); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(is)); builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, scopes); } else { builder = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, googleClientId, googleClientSecret, scopes); } String accessType = "online"; if (DeployManagerUtil.isDeployed(_GOOGLE_DRIVE_CONTEXT)) { accessType = "offline"; } builder.setAccessType(accessType); builder.setApprovalPrompt("force"); return builder.build(); }
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 ww w. ja v a 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.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// ww w. ja va 2 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(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.madhu.oauth2.OAuth2Sample.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private static Credential authorize() throws Exception { // load client secrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(OAuth2Sample.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/ " + "into oauth2-cmdline-sample/src/main/resources/client_secrets.json"); System.exit(1);/* w w w . j av a2s. com*/ } // 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"); }
From source file:com.mkyong.controller.Utils.java
License:Apache License
private static GoogleClientSecrets getClientSecrets_cal() throws IOException { if (clientSecrets_cal == null) { clientSecrets_cal = GoogleClientSecrets.load(JSON_FACTORY_CAL, new InputStreamReader(Utils.class.getResourceAsStream("/client_secrets.json"))); Preconditions.checkArgument(/*w w w . j a v a 2 s . c om*/ !clientSecrets_cal.getDetails().getClientId().startsWith("Enter ") && !clientSecrets_cal.getDetails().getClientSecret().startsWith("Enter "), "Download client_secrets.json file from https://code.google.com/apis/console/?api=plus " + "into plus-preview-appengine-sample/src/main/resources/client_secrets.json"); } return clientSecrets_cal; }
From source file:com.mmi.appengine.utils.ServiceUtils.java
License:Apache License
public static GoogleClientSecrets getClientCredential() throws IOException { if (clientSecrets == null) { clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, ServiceUtils.class.getResourceAsStream("/client_secrets.json")); Preconditions.checkArgument(/*from w w w . j av a 2s. c o m*/ !clientSecrets.getDetails().getClientId().startsWith("Enter ") && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "), "Enter Client ID and Secret from https://code.google.com/apis/console/?api=bigquery " + "into bigquery-appengine-sample/src/main/resources/client_secrets.json"); } return clientSecrets; }
From source file:com.mxgraph.online.dredit.DrEditServlet.java
License:Apache License
/** * Loads the secrets./* ww w .ja v a2s . c om*/ */ protected void updateSecrets() { if (secrets == null) { try { secrets = GoogleClientSecrets.load(JSON_FACTORY, getClientSecretsStream()); } catch (IOException e) { throw new RuntimeException("client_secrets.json is missing or invalid."); } } }
From source file:com.mycompany.gmailtest.view.MessageView.java
public static void connectToApi(String[] args) throws IOException { httpTransport = new NetHttpTransport(); jsonFactory = new JacksonFactory(); String CLIENT_SECRET_PATH = MessageView.class.getClassLoader().getResource("/client_secret.json").getPath(); clientSecrets = GoogleClientSecrets.load(jsonFactory, new FileReader(CLIENT_SECRET_PATH)); // Allow user to authorize via url. flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, Arrays.asList(SCOPE)).setAccessType("online").setApprovalPrompt("auto").build(); String url = flow.newAuthorizationUrl().setRedirectUri(callbackUrl).build(); updateData = true;//from w w w . j a v a 2s.c o m //Redirect user to the main page ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); context.redirect(url); }