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:name.herve.gcms.CalendarWrapper.java
License:Open Source License
private Credential authorize() throws Exception { GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(getClass().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);//from www . j av a2 s. c o m } FileCredentialStore credentialStore = new FileCredentialStore( new File(System.getProperty("user.home"), ".credentials/calendar.json"), jsonFactory); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setCredentialStore(credentialStore) .build(); return new AuthorizationCodeInstalledApp(flow, new GooglePromptReceiver()).authorize("user"); }
From source file:net.starschema.clouddb.cmdlineverification.Oauth2Bigquery.java
License:Open Source License
/** * Creates GoogleClientsecrets "installed application" instance based on * given Clientid, and Clientsecret//w ww. j a v a 2 s .c o m * * @param jsonFactory * @param clientid * @param clientsecret * @return GoogleClientsecrets of "installed application" * @throws IOException */ private static GoogleClientSecrets loadClientSecrets(JsonFactory jsonFactory, String clientid, String clientsecret) throws IOException { if (Oauth2Bigquery.clientSecrets == null) { String clientsecrets = "{\n" + "\"installed\": {\n" + "\"client_id\": \"" + clientid + "\",\n" + "\"client_secret\":\"" + clientsecret + "\",\n" + "\"redirect_uris\": [\"http://localhost\", \"urn:ietf:oauth:2.0:oob\"],\n" + "\"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n" + "\"token_uri\": \"https://accounts.google.com/o/oauth2/token\"\n" + "}\n" + "}"; StringReader stringReader = new StringReader(clientsecrets); Oauth2Bigquery.clientSecrets = GoogleClientSecrets.load(jsonFactory, stringReader); } return Oauth2Bigquery.clientSecrets; }
From source file:net.tinyportal.service.google.api.Gapi.java
License:Open Source License
/** * Reads client_secrets.json and creates a GoogleClientSecrets object. * @return A GoogleClientsSecrets object. *//*from www .j a v a 2s. c o m*/ private GoogleClientSecrets getClientSecrets(ServletContext servletContext) { // TODO: do not read on each request InputStream stream = servletContext.getResourceAsStream(CLIENT_SECRETS_FILE_PATH); try { return GoogleClientSecrets.load(JSON_FACTORY, stream); } catch (IOException e) { throw new RuntimeException("No client_secrets.json found"); } }
From source file:net.tirasa.connid.bundles.googleapps.Main.java
License:Open Source License
static Map<String, Object> getConfigurationMap(File clientJson) throws IOException, URISyntaxException { GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader(clientJson)); Credential credential = new AuthorizationCodeInstalledApp( new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) .setAccessType("offline").setApprovalPrompt("force") .setDataStoreFactory(MemoryDataStoreFactory.getDefaultInstance()).build(), new AbstractPromptReceiver() { @Override/* w w w . ja v a2 s. c o m*/ public String getRedirectUri() throws IOException { return GoogleOAuthConstants.OOB_REDIRECT_URI; } }).authorize("user"); Map<String, Object> configMap = new LinkedHashMap<String, Object>(3); configMap.put("clientId", clientSecrets.getDetails().getClientId()); configMap.put("clientSecret", clientSecrets.getDetails().getClientSecret()); configMap.put("refreshToken", credential.getRefreshToken()); return configMap; }
From source file:nl.dukesolutions.picasa.fxml.OAuth2.java
License:Apache License
/** Authorizes the installed application to access user's protected data. */ private Credential authorize() throws Exception { // load client secrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(OAuth2.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 picasauploader/src/main/resources/client_secrets.json"); System.exit(1);// w w w . j a v 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"); }
From source file:nurseconsole1cserver.Notifications.ServerEvents.java
private static Credential authorize() throws Exception { // load client secrets // GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, // new InputStreamReader(CalendarNotification.class.getResourceAsStream("\\client_secrets.json"))); GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(CLIENT_SECRETS)); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory) .build();//from w w w. j a va 2 s . c o m // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:org.ado.minesync.translation.drive.DriveClientFactory.java
License:Open Source License
/** * Authorizes the installed application to access user's protected data. *//*from www . j a v a 2 s. co m*/ private static Credential authorize() throws Exception { // load client secrets GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(DriveClientFactory.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { throw new IllegalArgumentException("Invalid client_secrets info"); } Set<String> scopes = new HashSet<String>(); scopes.add(DriveScopes.DRIVE); scopes.add(DriveScopes.DRIVE_APPDATA); scopes.add(DriveScopes.DRIVE_FILE); scopes.add(DriveScopes.DRIVE_METADATA_READONLY); scopes.add(DriveScopes.DRIVE_READONLY); 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:org.alfresco.integrations.google.docs.service.GoogleDocsServiceImpl.java
License:Open Source License
public void init() throws IOException { httpTransport = new NetHttpTransport(); jsonFactory = new JacksonFactory(); clientSecrets = GoogleClientSecrets.load(jsonFactory, new InputStreamReader(GoogleDocsServiceImpl.class.getResourceAsStream("client_secret.json"))); }
From source file:org.apache.beam.sdk.util.Credentials.java
License:Apache License
/** * Loads OAuth2 credential from client secrets, which may require an * interactive authorization prompt.// w w w. java 2 s .c om */ private static Credential getCredentialFromClientSecrets(GcpOptions options, Collection<String> scopes) throws IOException, GeneralSecurityException { String clientSecretsFile = options.getSecretsFile(); checkArgument(clientSecretsFile != null); HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jsonFactory = JacksonFactory.getDefaultInstance(); GoogleClientSecrets clientSecrets; try { clientSecrets = GoogleClientSecrets.load(jsonFactory, new FileReader(clientSecretsFile)); } catch (IOException e) { throw new RuntimeException("Could not read the client secrets from file: " + clientSecretsFile, e); } FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory( new java.io.File(options.getCredentialDir())); GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, jsonFactory, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory) .setTokenServerUrl(new GenericUrl(options.getTokenServerUrl())) .setAuthorizationServerEncodedUrl(options.getAuthorizationServerEncodedUrl()).build(); // The credentialId identifies the credential if we're using a persistent // credential store. Credential credential = new AuthorizationCodeInstalledApp(flow, new PromptReceiver()) .authorize(options.getCredentialId()); LOG.info("Got credential from client secret"); return credential; }
From source file:org.argrr.extractor.gdrive.downloader.DriveApi.java
License:Open Source License
/** Authorizes the installed application to access user's protected data. */ public static Credential authorize() throws Exception { GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(Config.getDriveApi())); 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 a v a2 s .co m*/ } // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE)).setDataStoreFactory(dataStoreFactory) .setTransport(httpTransport).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }