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());
}
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());
}
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;
}
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));
}
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());
}
Aggregations