Search in sources :

Example 6 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project teammates by TEAMMATES.

the class GmailServiceMaker method authorizeAndCreateCredentials.

/**
 * Authorizes the user and creates an authorized Credential.
 * @return an authorized Credential
 */
private Credential authorizeAndCreateCredentials() throws IOException {
    GoogleClientSecrets clientSecrets = loadClientSecretFromJson();
    GoogleAuthorizationCodeFlow flow = buildFlow(clientSecrets);
    if (shouldUseFreshCredentials) {
        flow.getCredentialDataStore().delete(username);
    }
    if (flow.getCredentialDataStore().get(username) == null) {
        System.out.println("Please login as: " + username);
    }
    return getCredentialFromFlow(flow);
}
Also used : GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets)

Example 7 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project teammates by TEAMMATES.

the class GmailServiceMaker method buildFlow.

private GoogleAuthorizationCodeFlow buildFlow(GoogleClientSecrets clientSecrets) throws IOException {
    // if the scopes need to change, the user will need to manually delete
    // <TestProperties.TEST_GMAIL_API_FOLDER>/StoredCredential
    final List<String> scopes = Arrays.asList(GmailScopes.GMAIL_READONLY, GmailScopes.GMAIL_MODIFY);
    FileDataStoreFactory dataStoreFactory = new FileDataStoreFactory(new File(TestProperties.TEST_GMAIL_API_FOLDER));
    return new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setDataStoreFactory(dataStoreFactory).setAccessType("offline").build();
}
Also used : FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) File(java.io.File)

Example 8 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project muikku by otavanopisto.

the class GoogleCalendarClient method getAccessTokenCredential.

@SuppressWarnings("unused")
private GoogleCredential getAccessTokenCredential() {
    AccessToken googleAccessToken = sessionController.getOAuthAccessToken("google");
    if (googleAccessToken != null) {
        Details details = new Details();
        details.setClientId("-");
        details.setClientSecret("-");
        GoogleClientSecrets secrets = new GoogleClientSecrets();
        secrets.setWeb(details);
        return new GoogleCredential.Builder().setClientSecrets(secrets).setTransport(TRANSPORT).setJsonFactory(JSON_FACTORY).build().setAccessToken(googleAccessToken.getToken());
    }
    return null;
}
Also used : Details(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.Details) AccessToken(fi.otavanopisto.muikku.session.AccessToken) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential)

Example 9 with GoogleClientSecrets

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

the class GoogleCalendarAuth 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(CalendarScopes.CALENDAR)).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 10 with GoogleClientSecrets

use of com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets in project Saber-Bot by notem.

the class GoogleAuth method newAuthorizationUrl.

/**
 * @return
 * @throws IOException
 */
public static String newAuthorizationUrl() throws IOException {
    // Load client secrets.
    InputStream in = new FileInputStream(Main.getBotSettingsManager().getGoogleOAuthSecret());
    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();
    return flow.newAuthorizationUrl().setScopes(SCOPES).setAccessType("offline").setClientId(clientSecrets.getDetails().getClientId()).setRedirectUri(clientSecrets.getDetails().getRedirectUris().get(0)).toString();
}
Also used : GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets)

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