Example usage for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets getDetails

List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets getDetails

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.auth.oauth2 GoogleClientSecrets getDetails.

Prototype

public Details getDetails() 

Source Link

Document

Returns the details for either installed or web applications.

Usage

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);//from  w w w  . jav  a2s.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");
}

From source file:org.forgerock.openicf.connectors.googleapps.Main.java

License:Open Source License

static Map<String, Object> getConfigurationMap(File clientJson) throws IOException, URISyntaxException {
    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 .ja  v a  2  s.com
                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:org.gcaldaemon.core.GCalUtilitiesV3.java

License:Apache License

private static Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(
            ClassLoader.getSystemClassLoader().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=calendar "
                + "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
        System.exit(1);//from w  ww.  j  a v a 2  s .co m
    }
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:org.iminer.components.publication.pdf.GoogleClient.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,
            GoogleClient.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/?api=calendar "
                + "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
        System.exit(1);/*from   w w  w  .  jav  a 2 s.co m*/
    }
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(new File(
            "E:\\My Projects\\Google\\api-sample\\google-api-java-client-samples\\calendar-cmdline-sample",
            ".credentials/calendar.json"), JSON_FACTORY);
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setCredentialStore(credentialStore)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:raspi_ui.backend.calendar.CalendarData.java

License:Apache License

private static Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(CalendarData.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/?api=calendar "
                + "into calendar-cmdline-sample/src/main/resources/client_secrets.json");
        System.exit(1);//  ww  w. j a  v a  2s  .c om
    }
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, Collections.singleton(CalendarScopes.CALENDAR)).setDataStoreFactory(dataStoreFactory)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:ru.tiis.library.service.impl.GDriveService.java

License:Apache License

private static GoogleAuthorizationCodeFlow buildAuthorizationFlow() throws IOException {

    // load client secrets
    java.io.File credentials = new java.io.File(
            GDriveService.class.getResource("upload-service-credentials.json").getFile());
    log.info("Data store dir : " + DATA_STORE_DIR);
    FileInputStream fis = new FileInputStream(credentials);
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(fis));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {

        log.warn("Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive "
                + "into drive-cmdline-sample/src/main/resources/client_secrets.json");
        return null;
    }//from   ww  w . j a v a 2 s .c  om
    log.info("Google client secrets loaded");

    // set up authorization flow configuration
    log.info("Building authorization code flow...");
    GoogleAuthorizationCodeFlow.Builder flowBuilder = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
            JSON_FACTORY, clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE))
                    .setDataStoreFactory(dataStoreFactory).setAccessType("offline").setApprovalPrompt("force");
    GoogleAuthorizationCodeFlow flow = flowBuilder.build();
    log.info("Building authorization code flow - done");

    return flow;
}

From source file:Scrappers.Auth.java

/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes              list of scopes needed to run youtube upload.
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 *///from  ww w . j  a v  a  2 s  .  c  o  m
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

    // Load client secrets.
    Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

    // 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://console.developers.google.com/project/_/apiui/credential "
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(
            new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, scopes).setCredentialDataStore(datastore).build();

    // Build the local server and bind it to port 8080
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}

From source file:tv.bioscope.taskqueue.TaskQueueWorker.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 = new GoogleClientSecrets();
    GoogleClientSecrets.Details installed = new GoogleClientSecrets.Details();
    installed.setClientId(CLIENT_ID);//  w w  w. j  a v  a  2s  . c  o  m
    installed.setClientSecret(CLIENT_SECRET);
    clientSecrets.setInstalled(installed);

    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=taskqueue into "
                        + "taskqueue-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(TaskqueueScopes.TASKQUEUE))
                    .setDataStoreFactory(dataStoreFactory).build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:utils.Auth.java

License:Open Source License

/**
 * Authorizes the installed application to access user's protected data.
 *
 * @param scopes              list of scopes needed to run youtube upload.
 * @param credentialDatastore name of the credential datastore to cache OAuth tokens
 *///from  ww w .j av a2  s  . co  m
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {

    // Load client secrets.
    Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);

    // 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 src/main/resources/client_secrets.json");
        System.exit(1);
    }

    // This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(
            new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, scopes).setCredentialDataStore(datastore).build();

    // Build the local server and bind it to port 8080
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}

From source file:wmg.datagrabber.google.youtubegrabber.cmdline.YouTubeGrabber.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
private Boolean authorize() {
    // load client secrets
    GoogleClientSecrets clientSecrets = null;
    GoogleAuthorizationCodeFlow flow = null;
    try {//from ww  w  .j  a  v  a  2s.  c om
        clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
                new InputStreamReader(YouTubeGrabber.class.getResourceAsStream("/client_secrets.json")));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Overwrite the src/main/resources/client_secrets.json file with the client secrets file "
                        + "you downloaded from the Quickstart tool or manually enter your Client ID and Secret "
                        + "from https://code.google.com/apis/console/?api=youtube#project:498789533454 "
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }
    Set<String> scopes = new HashSet<String>();
    scopes.add(YouTubeScopes.YOUTUBE);
    scopes.add(YouTubeScopes.YOUTUBE_READONLY);
    scopes.add(YouTubeScopes.YOUTUBE_UPLOAD);
    scopes.add(YouTubeScopes.YOUTUBEPARTNER);
    scopes.add(YouTubeScopes.YOUTUBEPARTNER_CHANNEL_AUDIT);

    try {
        flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, scopes)
                .setDataStoreFactory(dataStoreFactory).build();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    credential.setExpiresInSeconds(1000L);
    return true;
}