Search in sources :

Example 6 with TokenSecretAuthData

use of org.datatransferproject.types.transfer.auth.TokenSecretAuthData in project data-transfer-project by google.

the class OAuth1DataGenerator method generateConfiguration.

@Override
public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, String id) {
    String callback = (Strings.isNullOrEmpty(callbackBaseUrl)) ? OUT_OF_BOUNDS_CALLBACK : callbackBaseUrl;
    OAuthGetTemporaryToken tempTokenRequest = new OAuthGetTemporaryToken(config.getRequestTokenUrl());
    tempTokenRequest.callback = callback;
    tempTokenRequest.transport = httpTransport;
    tempTokenRequest.consumerKey = clientId;
    tempTokenRequest.signer = config.getRequestTokenSigner(clientSecret);
    config.getAdditionalUrlParameters(dataType, mode, OAuth1Step.REQUEST_TOKEN).forEach(tempTokenRequest::set);
    TokenSecretAuthData authData;
    try {
        // get request token
        OAuthCredentialsResponse tempTokenResponse = tempTokenRequest.execute();
        authData = new TokenSecretAuthData(tempTokenResponse.token, tempTokenResponse.tokenSecret);
    } catch (IOException e) {
        monitor.severe(() -> "Error retrieving request token", e);
        return null;
    }
    OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(config.getAuthorizationUrl());
    authorizeUrl.temporaryToken = authData.getToken();
    config.getAdditionalUrlParameters(dataType, mode, OAuth1Step.AUTHORIZATION).forEach(authorizeUrl::set);
    String url = authorizeUrl.build();
    return new AuthFlowConfiguration(url, getTokenUrl(), AuthProtocol.OAUTH_1, authData);
}
Also used : AuthFlowConfiguration(org.datatransferproject.spi.api.types.AuthFlowConfiguration) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) OAuthGetTemporaryToken(com.google.api.client.auth.oauth.OAuthGetTemporaryToken) IOException(java.io.IOException) OAuthAuthorizeTemporaryTokenUrl(com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl) OAuthCredentialsResponse(com.google.api.client.auth.oauth.OAuthCredentialsResponse)

Example 7 with TokenSecretAuthData

use of org.datatransferproject.types.transfer.auth.TokenSecretAuthData in project data-transfer-project by google.

the class FlickrPhotosExporterTest method exportAlbumInitial.

@Test
public void exportAlbumInitial() throws FlickrException {
    // set up auth, flickr service
    when(user.getId()).thenReturn("userId");
    when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
    when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
    when(flickr.getPhotosInterface()).thenReturn(photosInterface);
    when(flickr.getAuthInterface()).thenReturn(authInterface);
    // setup photoset
    Photoset photoset = FlickrTestUtils.initializePhotoset("photosetId", "title", "description");
    // setup photoset list (aka album view)
    int page = 1;
    Photosets photosetsList = new Photosets();
    photosetsList.setPage(page);
    photosetsList.setPages(page + 1);
    photosetsList.setPhotosets(Collections.singletonList(photoset));
    when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetsList);
    // run test
    FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr, TransferServiceConfig.getDefaultInstance());
    AuthData authData = new TokenSecretAuthData("token", "secret");
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), authData, Optional.empty());
    // make sure album and photo information is correct
    assertThat(result.getExportedData().getPhotos()).isEmpty();
    Collection<PhotoAlbum> albums = result.getExportedData().getAlbums();
    assertThat(albums.size()).isEqualTo(1);
    assertThat(albums).containsExactly(new PhotoAlbum("photosetId", "title", "description"));
    // check continuation information
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    assertThat(continuationData.getPaginationData()).isInstanceOf(IntPaginationToken.class);
    assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
    Collection<? extends ContainerResource> subResources = continuationData.getContainerResources();
    assertThat(subResources.size()).isEqualTo(1);
    assertThat(subResources).containsExactly(new IdOnlyContainerResource("photosetId"));
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) AuthData(org.datatransferproject.types.transfer.auth.AuthData) IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) Token(org.scribe.model.Token) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Test(org.junit.Test)

Example 8 with TokenSecretAuthData

use of org.datatransferproject.types.transfer.auth.TokenSecretAuthData in project data-transfer-project by google.

the class FlickrPhotosExporterTest method exportPhotosFromPhotoset.

@Test
public void exportPhotosFromPhotoset() throws FlickrException {
    // set up auth, flickr service
    when(user.getId()).thenReturn("userId");
    when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
    when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
    when(flickr.getPhotosInterface()).thenReturn(photosInterface);
    when(flickr.getAuthInterface()).thenReturn(authInterface);
    // getting photos from a set with id photosetsId and page 1
    int page = 1;
    String photosetsId = "photosetsId";
    ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
    // make lots of photos and add them to PhotoList (also adding pagination information)
    int numPhotos = 4;
    PhotoList<Photo> photosList = new PhotoList<>();
    for (int i = 0; i < numPhotos; i++) {
        photosList.add(FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE));
    }
    photosList.setPage(page);
    photosList.setPages(page + 1);
    when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(photosList);
    // run test
    FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr, TransferServiceConfig.getDefaultInstance());
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), Optional.of(exportInformation));
    assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos);
    assertThat(result.getExportedData().getAlbums()).isEmpty();
    ContinuationData continuationData = (ContinuationData) result.getContinuationData();
    assertThat(continuationData.getContainerResources()).isEmpty();
    assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) Token(org.scribe.model.Token) Photo(com.flickr4java.flickr.photos.Photo) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ExportInformation(org.datatransferproject.types.common.ExportInformation) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoList(com.flickr4java.flickr.photos.PhotoList) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Aggregations

TokenSecretAuthData (org.datatransferproject.types.transfer.auth.TokenSecretAuthData)8 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)5 Test (org.junit.Test)5 Token (org.scribe.model.Token)4 UUID (java.util.UUID)3 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)3 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Photoset (com.flickr4java.flickr.photosets.Photoset)2 OAuthCredentialsResponse (com.google.api.client.auth.oauth.OAuthCredentialsResponse)2 IOException (java.io.IOException)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)2 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)2 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)2 Photo (com.flickr4java.flickr.photos.Photo)1 PhotoList (com.flickr4java.flickr.photos.PhotoList)1 Photosets (com.flickr4java.flickr.photosets.Photosets)1 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)1 OAuthAuthorizeTemporaryTokenUrl (com.google.api.client.auth.oauth.OAuthAuthorizeTemporaryTokenUrl)1