Search in sources :

Example 1 with AuthFlowConfiguration

use of org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration in project data-transfer-project by google.

the class GoogleAuthDataGeneratorTest method generateConfigurationExport.

@Test
public void generateConfigurationExport() {
    GoogleAuthDataGenerator generator = new GoogleAuthDataGenerator("redirect", appCredentials, httpTransport, null, "calendar", AuthMode.EXPORT);
    AuthFlowConfiguration config = generator.generateConfiguration("http://localhost/test", "54321");
    Assert.assertEquals("https://accounts.google.com/o/oauth2/auth?" + "access_type=offline&approval_prompt=force&client_id=dummy-id" + "&redirect_uri=http://localhost/testredirect&response_type=code" + "&scope=" + CalendarScopes.CALENDAR_READONLY + "&state=NTQzMjE%3D", config.getUrl());
}
Also used : AuthFlowConfiguration(org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration) Test(org.junit.Test)

Example 2 with AuthFlowConfiguration

use of org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration in project data-transfer-project by google.

the class GoogleAuthDataGeneratorTest method generateConfigurationImport.

@Test
public void generateConfigurationImport() {
    GoogleAuthDataGenerator generator = new GoogleAuthDataGenerator("redirect", appCredentials, httpTransport, null, "calendar", AuthMode.IMPORT);
    AuthFlowConfiguration config = generator.generateConfiguration("http://localhost/test", "54321");
    Assert.assertEquals("https://accounts.google.com/o/oauth2/auth?" + "access_type=offline&approval_prompt=force&client_id=dummy-id" + "&redirect_uri=http://localhost/testredirect&response_type=code" + "&scope=" + CalendarScopes.CALENDAR + "&state=NTQzMjE%3D", config.getUrl());
}
Also used : AuthFlowConfiguration(org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration) Test(org.junit.Test)

Example 3 with AuthFlowConfiguration

use of org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration 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)

Example 4 with AuthFlowConfiguration

use of org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration in project data-transfer-project by google.

the class FlickrAuthDataGenerator method generateConfiguration.

@Override
public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, String id) {
    AuthInterface authInterface = flickr.getAuthInterface();
    Token token = authInterface.getRequestToken(callbackBaseUrl + "/callback1/flickr");
    String url = authInterface.getAuthorizationUrl(token, Permission.WRITE);
    return new AuthFlowConfiguration(url, toAuthData(token));
}
Also used : AuthFlowConfiguration(org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration) AuthInterface(com.flickr4java.flickr.auth.AuthInterface) Token(org.scribe.model.Token)

Example 5 with AuthFlowConfiguration

use of org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration in project data-transfer-project by google.

the class SetupHandler method handleImportSetup.

private DataTransferResponse handleImportSetup(Headers headers, PortabilityJob job, UUID jobId) throws IOException {
    String exportAuthCookie = ReferenceApiUtils.getCookie(headers, JsonKeys.EXPORT_AUTH_DATA_COOKIE_KEY);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(exportAuthCookie), "Export auth cookie required");
    // Initial auth flow url
    AuthDataGenerator generator = registry.getAuthDataGenerator(job.importService(), job.transferDataType(), AuthMode.IMPORT);
    Preconditions.checkNotNull(generator, "Generator not found for type: %s, service: %s", job.transferDataType(), job.importService());
    String encodedJobId = ReferenceApiUtils.encodeJobId(jobId);
    AuthFlowConfiguration authFlowConfiguration = generator.generateConfiguration(baseApiUrl, encodedJobId);
    Preconditions.checkNotNull(authFlowConfiguration, "AuthFlowConfiguration not found for type: %s, service: %s", job.transferDataType(), job.importService());
    // If present, store initial auth data for export services, e.g. used for oauth1
    if (authFlowConfiguration.getInitialAuthData() != null) {
        // Retrieve and parse the session key from the job
        String sessionKey = job.jobAuthorization().sessionSecretKey();
        SecretKey key = symmetricKeyGenerator.parse(BaseEncoding.base64Url().decode(sessionKey));
        // Ensure intial auth data for import has not already been set
        Preconditions.checkState(Strings.isNullOrEmpty(job.jobAuthorization().encryptedInitialImportAuthData()));
        // Serialize and encrypt the initial auth data
        String serialized = objectMapper.writeValueAsString(authFlowConfiguration.getInitialAuthData());
        String encryptedInitialAuthData = EncrypterFactory.create(key).encrypt(serialized);
        // Add the serialized and encrypted initial auth data to the job authorization
        JobAuthorization updatedJobAuthorization = job.jobAuthorization().toBuilder().setEncryptedInitialImportAuthData(encryptedInitialAuthData).build();
        // Persist the updated PortabilityJob with the updated JobAuthorization
        PortabilityJob updatedPortabilityJob = job.toBuilder().setAndValidateJobAuthorization(updatedJobAuthorization).build();
        store.updateJob(jobId, updatedPortabilityJob);
    }
    return new DataTransferResponse(job.exportService(), job.importService(), job.transferDataType(), Status.INPROCESS, // Redirect to auth page of import service
    authFlowConfiguration.getUrl());
}
Also used : AuthFlowConfiguration(org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration) AuthDataGenerator(org.dataportabilityproject.spi.gateway.auth.AuthDataGenerator) JobAuthorization(org.dataportabilityproject.spi.cloud.types.JobAuthorization) PortabilityJob(org.dataportabilityproject.spi.cloud.types.PortabilityJob) SecretKey(javax.crypto.SecretKey) DataTransferResponse(org.dataportabilityproject.types.client.transfer.DataTransferResponse)

Aggregations

AuthFlowConfiguration (org.dataportabilityproject.spi.gateway.types.AuthFlowConfiguration)6 SecretKey (javax.crypto.SecretKey)2 JobAuthorization (org.dataportabilityproject.spi.cloud.types.JobAuthorization)2 PortabilityJob (org.dataportabilityproject.spi.cloud.types.PortabilityJob)2 AuthDataGenerator (org.dataportabilityproject.spi.gateway.auth.AuthDataGenerator)2 DataTransferResponse (org.dataportabilityproject.types.client.transfer.DataTransferResponse)2 Test (org.junit.Test)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AuthInterface (com.flickr4java.flickr.auth.AuthInterface)1 Desktop (java.awt.Desktop)1 HttpCookie (java.net.HttpCookie)1 URI (java.net.URI)1 OkHttpClient (okhttp3.OkHttpClient)1 MicrosoftAuthDataGenerator (org.dataportabilityproject.auth.microsoft.MicrosoftAuthDataGenerator)1 CreateJobActionRequest (org.dataportabilityproject.gateway.action.createjob.CreateJobActionRequest)1 CreateJobActionResponse (org.dataportabilityproject.gateway.action.createjob.CreateJobActionResponse)1 DataTransferRequest (org.dataportabilityproject.types.client.transfer.DataTransferRequest)1 TokenAuthData (org.dataportabilityproject.types.transfer.auth.TokenAuthData)1 Token (org.scribe.model.Token)1