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.cloudsearch.oauth.CredentialMediator.java
License:Apache License
/** * Creates a new CredentialsManager for the given HTTP request. * * @param request Request in which session credentials are stored. * @param clientSecretsStream Stream of client_secrets.json. * @throws InvalidClientSecretsException *//*from w w w .j ava 2 s .c o m*/ public CredentialMediator(RequestModel request, InputStream clientSecretsStream, Collection<String> scopes) throws InvalidClientSecretsException { this.request = request; this.scopes = scopes; if (credentialStore == null) { //this.credentialStore = new MemoryCredentialStore(); credentialStore = new GoogleDynamoDBCredentialStore(); } try { secrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretsStream); } catch (IOException e) { throw new InvalidClientSecretsException("client_secrets.json is missing or invalid."); } }
From source file:com.compguide.web.google.calendar.api.GoogleCalendar.java
/** * Loads client secrets and Creates an Google Authorization Code Flow * object.//from w w w. j a va2 s . c om * * @return an GoogleAuthorizationCodeFlow object. * @throws IOException */ public static GoogleAuthorizationCodeFlow authorizationCodeFlow(String accessType) throws IOException { // Load client secrets. InputStream in = GoogleCalendar.class.getResourceAsStream("/client_id.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(accessType).build(); return flow; }
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.danis.latihan.angularjs.DriveQuickstart.java
/** * Creates an authorized Credential object. * * @return an authorized Credential object. * @throws IOException//w ww . j a va 2s . co m */ public static Credential authorize() throws IOException { // Load client secrets. InputStream in = DriveQuickstart.class.getResourceAsStream("/client_secret_1.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") .setApprovalPrompt("force").build(); Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()) .authorize("user"); System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath()); return credential; }
From source file:com.dnalog.fmrp.google.GoogleClientCredentials.java
License:Apache License
public static GoogleClientSecrets loadClientSecrets(String clientSecretsPath) { try {/*from www . j ava 2 s .c om*/ return GoogleClientSecrets.load(new JacksonFactory(), new FileInputStream(clientSecretsPath)); } catch (Exception e) { System.out.println("Could not load client_secrets.json"); e.printStackTrace(); } return null; }
From source file:com.evolveum.polygon.connector.googleapps.Main.java
License:Open Source License
static Map<String, Object> getConfigurationMap(File clientJson) throws IOException, URISyntaxException, Exception { System.setProperty("https.protocols", "TLSv1.2"); 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/*ww w. j ava 2s .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:com.example.irvinmundo.weirdwords.FusionTablesSample.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(FusionTablesSample.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println(/*www.j a v a2 s . co m*/ "Enter Client ID and Secret from https://code.google.com/apis/console/?api=fusiontables " + "into fusiontables-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(FusiontablesScopes.FUSIONTABLES)) .setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.example.plusPreviewAppengineSample.Utils.java
License:Apache License
private static GoogleClientSecrets getClientSecrets() throws IOException { if (clientSecrets == null) { clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(Utils.class.getResourceAsStream("/client_secrets.json"))); Preconditions.checkArgument(/* ww w . jav a 2s. com*/ !clientSecrets.getDetails().getClientId().startsWith("Enter ") && !clientSecrets.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; }
From source file:com.example.samcarey.InsertFusionTables.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(InsertFusionTables.class.getResourceAsStream("/client_secrets.json"))); if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) { System.out.println(/*w w w . j a v a2 s .co m*/ "Enter Client ID and Secret from https://code.google.com/apis/console/?api=fusiontables " + "into fusiontables-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(FusiontablesScopes.FUSIONTABLES)) .setDataStoreFactory(dataStoreFactory).build(); // authorize return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); }
From source file:com.gemmystar.api.youtube.YoutubeService.java
License:Open Source License
/** * Authorizes the installed application to access user's protected data. * * @param scopes// w w w .j a va2 s. co m * list of scopes needed to run youtube upload. */ private Credential authorize() throws Exception { //if (apiJsonFile.exists() == false) { // throw new FileNotFoundException("file not found. " + apiJsonFile.getAbsolutePath()); //} if (authCodeInstalledApp == null) { synchronized (syncObj) { if (authCodeInstalledApp == null) { // Load client secrets. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader( YoutubeService.class.getResourceAsStream("/client_secret_gemmystar.json"))); // Checks that the defaults have been replaced (Default = // "Enter X here"). 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=youtube" + "into youtube-cmdline-uploadvideo-sample/src/main/resources/client_secrets.json"); System.exit(1); } // Set up file credential store. FileCredentialStore credentialStore = new FileCredentialStore( //new File(System.getProperty("user.home"), ".credentials/youtube-api-uploadvideo.json"), apiJsonFile, JSON_FACTORY); // Set up authorization code flow. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialStore(credentialStore).build(); // Build the local server and bind it to port 9099 LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(9099).build(); authCodeInstalledApp = new AuthorizationCodeInstalledApp(flow, localReceiver); } } } // Authorize. return authCodeInstalledApp.authorize("user"); }