use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow in project camel by apache.
the class InteractiveGoogleDriveClientFactory method authorize.
/**
* This method interactively creates the necessary authorization tokens on first run,
* and stores the tokens in the data store. Subsequent runs will no longer require interactivity
* as long as the credentials file is not removed.
*/
private Credential authorize(String clientId, String clientSecret, Collection<String> scopes) throws Exception {
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory, clientId, clientSecret, scopes).setDataStoreFactory(dataStoreFactory).setAccessType("offline").build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow in project OsmAnd-tools by osmandapp.
the class ExceptionAnalyzerMain method authorize.
/**
* Creates an authorized Credential object.
* @return an authorized Credential object.
* @throws IOException
*/
public static Credential authorize() throws IOException {
// Load client secrets.
InputStream in = ExceptionAnalyzerMain.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;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow in project data-transfer-project by google.
the class GoogleAuth method authorize.
private Credential authorize() throws IOException {
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = createFlow();
// authorize
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost(DOMAIN).setPort(PORT).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow in project DisCal-Discord-Bot by NovaFox161.
the class CalendarAuth method authorize.
/**
* Creates an authorized Credential object.
*
* @return an authorized Credential object.
* @throws IOException In the event authorization fails.
*/
private static Credential authorize() throws IOException {
// Load client secrets.
InputStream in = CalendarAuth.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");
Logger.getLogger().debug("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
return credential;
}
use of com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow in project selenium_java by sergueik.
the class Quickstart method authorize.
/**
* Creates an authorized Credential object.
* @return an authorized Credential object.
* @throws IOException
*/
public static Credential authorize() throws IOException {
// Load client secrets.
String fileName = "client_secret.json";
InputStream in = Quickstart.class.getResourceAsStream("/client_secret.json");
/*
in = Files.newInputStream(Paths.get(String.format("%s/src/main/resources/%s", System.getProperty("user.dir"), fileName)));
*/
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();
/*
Exception in thread "main" java.lang.IllegalArgumentException
at com.google.api.client.repackaged.com.google.common.base.Preconditions
.checkArgument(Preconditions.java:111)
at com.google.api.client.util.Preconditions.checkArgument(Preconditions.
java:37)
at com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets.getD
etails(GoogleClientSecrets.java:82)
at com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeF
low$Builder.<init>(GoogleAuthorizationCodeFlow.java:195)
at com.github.sergueik.Quickstart.authorize(Quickstart.java:82)
at com.github.sergueik.Quickstart.getSheetsService(Quickstart.java:99)
at com.github.sergueik.Quickstart.main(Quickstart.java:106)
*/
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
System.out.println("Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
return credential;
}
Aggregations