use of org.dataportabilityproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class MicrosoftAuthDataGenerator method generateAuthData.
public TokenAuthData generateAuthData(String callbackBaseUrl, String authCode, String id, AuthData initialAuthData, String extra) {
String redirectUrl = callbackBaseUrl + redirectPath;
String params = constructTokenParams(authCode, redirectUrl, "user.read", "Contacts.ReadWrite");
Request.Builder tokenReqBuilder = new Request.Builder().url(TOKEN_URL);
tokenReqBuilder.header("Content-Type", "application/x-www-form-urlencoded");
tokenReqBuilder.post(RequestBody.create(MediaType.parse("application/x-www-form-urlencoded"), params));
try (Response tokenResponse = httpClient.newCall(tokenReqBuilder.build()).execute()) {
ResponseBody tokenBody = tokenResponse.body();
if (tokenBody == null) {
// return type
throw new RuntimeException("Token body was null:" + tokenResponse.code() + ":" + "<empty body>");
}
String token = new String(tokenBody.bytes());
Map<String, String> map = mapper.reader().forType(Map.class).readValue(token);
String accessToken = map.get("access_token");
if (accessToken == null) {
// return type
throw new RuntimeException("Token body was null:" + tokenResponse.code() + ":" + "Not in params");
}
return new TokenAuthData(accessToken);
} catch (IOException e) {
// type
throw new RuntimeException(e);
}
}
use of org.dataportabilityproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class LocalExportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Exporter<TokenAuthData, ContactsModelWrapper> contacts = (Exporter<TokenAuthData, ContactsModelWrapper>) serviceProvider.getExporter("contacts");
ExportResult<ContactsModelWrapper> wrapper = contacts.export(UUID.randomUUID(), token);
}
use of org.dataportabilityproject.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class MicrosoftCalendarExportTest method setUp.
@Before
public void setUp() {
client = new OkHttpClient.Builder().build();
mapper = new ObjectMapper();
transformerService = new TransformerServiceImpl();
token = new TokenAuthData("token123");
server = new MockWebServer();
}
use of org.dataportabilityproject.types.transfer.auth.TokenAuthData 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.types.transfer.auth.TokenAuthData in project data-transfer-project by google.
the class LocalImportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("contacts");
ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
ImportResult result = contacts.importItem(UUID.randomUUID(), token, wrapper);
}
Aggregations