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);
}
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();
}
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;
}
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");
}
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();
}
Aggregations