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

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

Introduction

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

Prototype

public static GoogleClientSecrets load(JsonFactory jsonFactory, Reader reader) throws IOException 

Source Link

Document

Loads the client_secrets.json file from the given reader.

Usage

From source file:com.neology.google.AuthorizeGoogleUser.java

License:Open Source License

private static Credential authorize(String user) throws Exception {
    clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(
            AuthorizeGoogleUser.class.getResourceAsStream("/amelia-server/client_id.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/ "
                + "into oauth2-cmdline-sample/src/main/resources/client_secrets.json");
    }//from  w ww . j a  v a  2  s  .c om

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, SCOPES).setDataStoreFactory(dataStoreFactory).build();
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize(user);
}

From source file:com.niroshpg.android.gmail.GmailUtils.java

License:Apache License

static GoogleClientSecrets getClientCredential() throws IOException {
    if (clientSecrets == null) {
        clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
                new InputStreamReader(GmailUtils.class.getResourceAsStream("/client_secret.json")));
        Preconditions.checkArgument(/*from  www . j  a  va2  s.com*/
                !clientSecrets.getDetails().getClientId().startsWith("Enter ")
                        && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "),
                "Download client_secret.json file from https://code.google.com/apis/console/"
                        + "?api=calendar into calendar-appengine-sample/src/main/resources/client_secret.json");
    }
    return clientSecrets;
}

From source file:com.nokia.scbe.bestdayever.calendar.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,
            CalendarSample.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  ww w .  j a  va2  s  . com*/
    }
    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(
            new File(System.getProperty("user.home"), ".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:com.nokia.scbe.bestdayever.calendar.FreeBusyTimesRetriever.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
private Credential authorize() throws Exception {
    // load client secrets
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            CalendarSample.class.getResourceAsStream("/client_secrets.json"));

    // set up file credential store
    FileCredentialStore credentialStore = new FileCredentialStore(
            new File(System.getProperty("user.home"), ".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();/* ww w .jav a2 s . c om*/

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

From source file:com.poc.bigquery.ServiceUtils.java

License:Apache License

static GoogleClientSecrets getClientCredential() throws IOException {
    if (clientSecrets == null) {
        clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
                new InputStreamReader(ServiceUtils.class.getResourceAsStream("/client_secrets.json")));
        Preconditions.checkArgument(/*ww  w .j  a  v a  2 s.  c  o m*/
                !clientSecrets.getDetails().getClientId().startsWith("Enter ")
                        && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "),
                "Enter Client ID and Secret from https://code.google.com/apis/console/?api=bigquery "
                        + "into bigquery-appengine-sample/src/main/resources/client_secrets.json");
    }
    return clientSecrets;
}

From source file:com.preparatic.csvreaders.GoogleSheet.java

License:Apache License

/**
 * Creates an authorized Credential object.
 * //from w w  w.j  a v  a  2s .c o  m
 * @return an authorized Credential object.
 * @throws IOException
 */
private static Credential authorize() throws IOException {
    // Load client secrets.
    InputStream in = ReadGoogleSheet.class.getResourceAsStream("/client_secret.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").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.rabadancm.gtm.api.v2.AuthenticatorJson.java

private Credential authorize() throws Exception {
    // Load client secrets.
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(AuthenticatorJson.class.getResourceAsStream(CLIENT_SECRET_JSON_RESOURCE)));

    // Set up authorization code flow for all auth scopes.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, TagManagerScopes.all()).setDataStoreFactory(dataStoreFactory).build();

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

From source file:com.randstad.googlecalendarsync.Utils.java

License:Apache License

/** Authorizes the installed application to access user's protected data. */
public static Credential authorize(List<String> scopes) throws Exception {
    // Load client secrets.
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(SyncTokenSample.class.getResourceAsStream("/client_secrets.json")));
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter")) {
        System.out.println(/*from  ww  w.java 2  s.co  m*/
                "Overwrite the src/main/resources/client_secrets.json file with the client secrets file "
                        + "you downloaded from your Google Developers Console project.");
        System.exit(1);
    }

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY,
            clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).build();
    // Authorize.
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

From source file:com.sakadream.lib.email.gmail.auth.GmailAuthorize.java

private static Credential authorize() throws Exception {
    InputStream inFile = GmailAuthorize.class.getResourceAsStream("data");
    String dataString = IOUtils.toString(inFile, Charset.defaultCharset());
    String decryptedString = Security.decrypt(dataString);
    InputStream inString = new ByteArrayInputStream(decryptedString.getBytes());

    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(inString));

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
            clientSecrets, SCOPES).setDataStoreFactory(DATA_STORE_FACTORY).setAccessType("offline").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.sappe.ontrack.security.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 InputStreamReader(CalendarSample.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);/*w  w  w. j a v a2s.  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");
}