Search in sources :

Example 21 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project jbpm-work-items by kiegroup.

the class GoogleTasksAuth method authorize.

public Credential authorize(String clientSecretJSON) throws Exception {
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecretJSON));
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).build();
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
Also used : StringReader(java.io.StringReader) 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)

Example 22 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project jbpm-work-items by kiegroup.

the class GoogleMailAuth method authorize.

public Credential authorize(String clientSecretJSON) throws Exception {
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecretJSON));
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).setAccessType("offline").build();
    Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    return credential;
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) StringReader(java.io.StringReader) 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)

Example 23 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project jbpm-work-items by kiegroup.

the class GoogleSheetsAuth method authorize.

public Credential authorize(String clientSecretJSON) throws Exception {
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecretJSON));
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, Collections.singleton(SheetsScopes.SPREADSHEETS_READONLY)).build();
    return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
Also used : StringReader(java.io.StringReader) 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)

Example 24 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project jbpm-work-items by kiegroup.

the class GoogleDriveAuth method authorize.

public Credential authorize(String clientSecretJSON) throws Exception {
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new StringReader(clientSecretJSON));
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES).build();
    Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
    return credential;
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) StringReader(java.io.StringReader) 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)

Example 25 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project api-samples by youtube.

the class Auth method authorize.

/**
 * 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
 */
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");
}
Also used : FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) InputStreamReader(java.io.InputStreamReader) StoredCredential(com.google.api.client.auth.oauth2.StoredCredential) 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)

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