Search in sources :

Example 1 with MicrosoftAuthDataGenerator

use of org.dataportabilityproject.auth.microsoft.MicrosoftAuthDataGenerator in project data-transfer-project by google.

the class AuthTestDriver method getOAuthTokenCode.

/**
 * Performs an OAuth flow using the MicrosoftAuthDataGenerator, returning a token.
 *
 * @return the token
 */
public TokenAuthData getOAuthTokenCode() throws Exception {
    OkHttpClient client = TestHelper.createTestBuilder(callbackHost).build();
    ObjectMapper mapper = new ObjectMapper();
    MicrosoftAuthDataGenerator dataGenerator = new MicrosoftAuthDataGenerator("/response", () -> clientId, () -> secret, client, mapper, "contacts", AuthMode.EXPORT);
    AuthFlowConfiguration configuration = dataGenerator.generateConfiguration(callbackBase, "1");
    Desktop desktop = Desktop.getDesktop();
    desktop.browse(new URI(configuration.getUrl()));
    // Execute the request and retrieve the auth code.
    String authCode = retrieveAuthCode(client);
    // get the token
    TokenAuthData tokenData = dataGenerator.generateAuthData(callbackBase, authCode, "1", configuration.getInitialAuthData(), null);
    // System.out.println("TOKEN: " + tokenData.getToken());
    return tokenData;
}
Also used : AuthFlowConfiguration(org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration) OkHttpClient(okhttp3.OkHttpClient) Desktop(java.awt.Desktop) TokenAuthData(org.dataportabilityproject.types.transfer.auth.TokenAuthData) MicrosoftAuthDataGenerator(org.dataportabilityproject.auth.microsoft.MicrosoftAuthDataGenerator) URI(java.net.URI) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Desktop (java.awt.Desktop)1 URI (java.net.URI)1 OkHttpClient (okhttp3.OkHttpClient)1 MicrosoftAuthDataGenerator (org.dataportabilityproject.auth.microsoft.MicrosoftAuthDataGenerator)1 AuthFlowConfiguration (org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration)1 TokenAuthData (org.dataportabilityproject.types.transfer.auth.TokenAuthData)1