use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project pentaho-kettle by pentaho.
the class GoogleDriveFileObject method authorize.
private Credential authorize() throws IOException {
InputStream in = new FileInputStream(resolveCredentialsPath() + "/" + resourceBundle.getString("client.secrets"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").build();
Credential credential = new CustomAuthorizationCodeInstalledApp(flow, new CustomLocalServerReceiver()).authorize("user");
return credential;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project BachelorPraktikum by lucasbuschlinger.
the class Credentials method authorize.
/**
* Authorizes the client against the Google services.
* @param path - path to the credentials file
* @throws IOException - thrown if the credentials file could not be read/written
*/
public static void authorize(final String path) throws IOException {
File file = new File(Paths.get(path).toAbsolutePath().toString());
// Load client secrets.
FileInputStream fileInput = new FileInputStream(file);
Reader reader = new InputStreamReader(fileInput, Charset.defaultCharset());
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, reader);
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES).setDataStoreFactory(dataStoreFactory).setAccessType("offline").build();
credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project drbookings by DrBookings.
the class GoogleCalendarSync method authorize.
/**
* Authorizes the installed application to access user's protected data.
*/
private static Credential authorize() throws Exception {
// load client secrets
final GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(GoogleCalendarSync.class.getResourceAsStream("/client_secrets.json")));
if (clientSecrets.getDetails().getClientId().startsWith("Enter") || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
if (logger.isErrorEnabled()) {
logger.error("Enter Client ID and Secret from https://code.google.com/apis/console/?api=calendar " + "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
}
return null;
}
// set up authorization code flow
final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory).build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("557837674207-61uehop5b0u5enflhc7ata9a75sf731e.apps.googleusercontent.com");
}
Aggregations