use of org.datatransferproject.auth.microsoft.MicrosoftAuthServiceExtension in project data-transfer-project by google.
the class AuthTestDriver method getOAuthTokenCode.
/**
* Performs an OAuth flow using the general AuthDataGenerator, returning a token.
*
* @return the token
*/
public TokenAuthData getOAuthTokenCode() throws Exception {
OkHttpClient client = TestHelper.createTestBuilder(callbackHost).build();
AuthDataGenerator authDataGenerator = new MicrosoftAuthServiceExtension().getAuthDataGenerator("CONTACTS", AuthMode.EXPORT);
AuthFlowConfiguration configuration = authDataGenerator.generateConfiguration(callbackBase, "1");
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(configuration.getAuthUrl()));
// Execute the request and retrieve the auth code.
String authCode = retrieveAuthCode(client);
// get the token
TokenAuthData tokenData = (TokenAuthData) authDataGenerator.generateAuthData(callbackBase, authCode, "1", configuration.getInitialAuthData(), null);
// System.out.println("TOKEN: " + tokenData.getToken());
return tokenData;
}
Aggregations