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:fr.acxio.tools.agia.google.GoogleDriveServiceImpl.java

License:Apache License

protected Credential authorize() throws GoogleException, GeneralSecurityException, IOException {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            clientSecretsResource.getInputStream());
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        LOGGER.error("Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive "
                + "into " + clientSecretsResource.getFile().getAbsolutePath());
        throw new GoogleException("ClientSecrets not configured");
    }//from w  ww  .ja  v a 2 s. c  o  m
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(userCredentialStoreResource.getFile(),
            JSON_FACTORY);
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, Collections.singleton(DriveScopes.DRIVE_FILE)).setCredentialStore(credentialStore)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, verificationCodeReceiver).authorize(user);
}

From source file:fusiontables.FusionTablesSample.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
    String path = "/client_secrets.json";

    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(FusionTablesSample.class.getResourceAsStream(path)));

    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(/*from   w  w w. j av  a 2s  .com*/
                "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:google.registry.tools.AuthModule.java

License:Open Source License

@Provides
@OAuthClientId
String provideClientId(GoogleClientSecrets clientSecrets) {
    return clientSecrets.getDetails().getClientId();
}

From source file:GoogleAPI.DriveService.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
private static Credential authorize() throws Exception {
    // load client secrets
    InputStream in = DriveService.class.getResourceAsStream("/client_secret.json");
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
    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   ww  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_FILE)).setDataStoreFactory(dataStoreFactory)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:GooglePlus.PlusSample.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
public static Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            PlusSample.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=plus "
                + "into plus-cmdline-sample/src/main/resources/client_secrets.json");
        System.exit(1);//w ww.j av  a2s .c om
    }
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(
            new File(System.getProperty("user.home"), ".credentials/plus.json"), JSON_FACTORY);
    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, Collections.singleton(PlusScopes.PLUS_ME)).setCredentialStore(credentialStore)
                    .build();
    // authorize
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:me.tango.devops.google.CredentialsManager.java

License:Apache License

/**
 * Authorizes the installed application to access user's protected data.
 *//*w  ww .  j a  va 2  s .co m*/
public static Credential authorize() throws IOException {
    // Load client secrets.
    final byte[] bytes = Files.toByteArray(new File(clientSecretFile));
    final GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(new ByteArrayInputStream(bytes)));
    if (clientSecrets.getDetails().getClientId() == null
            || clientSecrets.getDetails().getClientSecret() == null) {
        throw new IllegalStateException("client_secrets not well formed.");
    }

    // Set up authorization code flow.
    // Ask for only the permissions you need. Asking for more permissions will
    // reduce the number of users who finish the process for giving you access
    // to their accounts. It will also increase the amount of effort you will
    // have to spend explaining to users what you are doing with their data.
    // Here we are listing all of the available scopes. You should remove scopes
    // that you are not actually using.
    final Set<String> scopes = new HashSet<String>();
    scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
    scopes.add(StorageScopes.DEVSTORAGE_READ_ONLY);
    scopes.add(StorageScopes.DEVSTORAGE_READ_WRITE);

    final GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
            JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build();
    // Authorize.
    final VerificationCodeReceiver receiver = AUTH_LOCAL_WEBSERVER ? new LocalServerReceiver()
            : new GooglePromptReceiver();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}

From source file:messenger.CalendarSample.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 FileInputStream("client_secrets.json_futuresbot"));
    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 www .  j  av  a  2  s .c  o  m*/
    }
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(new File("calendar.json_futuresbot"),
            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: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);/*  w w  w . ja  va 2 s .  c om*/
    }
    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.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.  j  ava 2 s .  co 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:org.ado.minesync.translation.drive.DriveClientFactory.java

License:Open Source License

/**
 * Authorizes the installed application to access user's protected data.
 *//* w  ww.j  av a2  s. c  o 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");
}