Search in sources :

Example 1 with MicrosoftAuthServiceExtension

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;
}
Also used : MicrosoftAuthServiceExtension(org.datatransferproject.auth.microsoft.MicrosoftAuthServiceExtension) AuthFlowConfiguration(org.datatransferproject.spi.api.types.AuthFlowConfiguration) AuthDataGenerator(org.datatransferproject.spi.api.auth.AuthDataGenerator) OkHttpClient(okhttp3.OkHttpClient) Desktop(java.awt.Desktop) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) URI(java.net.URI)

Aggregations

Desktop (java.awt.Desktop)1 URI (java.net.URI)1 OkHttpClient (okhttp3.OkHttpClient)1 MicrosoftAuthServiceExtension (org.datatransferproject.auth.microsoft.MicrosoftAuthServiceExtension)1 AuthDataGenerator (org.datatransferproject.spi.api.auth.AuthDataGenerator)1 AuthFlowConfiguration (org.datatransferproject.spi.api.types.AuthFlowConfiguration)1 TokenAuthData (org.datatransferproject.types.transfer.auth.TokenAuthData)1