Search in sources :

Example 26 with GoogleClientSecrets

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;
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) CustomAuthorizationCodeInstalledApp(org.pentaho.googledrive.vfs.util.CustomAuthorizationCodeInstalledApp) CustomLocalServerReceiver(org.pentaho.googledrive.vfs.util.CustomLocalServerReceiver) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets)

Example 27 with GoogleClientSecrets

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");
}
Also used : InputStreamReader(java.io.InputStreamReader) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 28 with GoogleClientSecrets

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");
}
Also used : InputStreamReader(java.io.InputStreamReader) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)

Aggregations

GoogleAuthorizationCodeFlow (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)26 GoogleClientSecrets (com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets)26 AuthorizationCodeInstalledApp (com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp)20 LocalServerReceiver (com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)20 Credential (com.google.api.client.auth.oauth2.Credential)10 InputStreamReader (java.io.InputStreamReader)9 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)6 StringReader (java.io.StringReader)6 InputStream (java.io.InputStream)5 File (java.io.File)4 StoredCredential (com.google.api.client.auth.oauth2.StoredCredential)3 GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)3 Details (com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.Details)2 FileInputStream (java.io.FileInputStream)2 FileReader (java.io.FileReader)2 Reader (java.io.Reader)2 GoogleTokenResponse (com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1 GsonFactory (com.google.api.client.json.gson.GsonFactory)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1