Permalink
Browse files

Add support for exporting Facebook photos (#587)

* Add support for exporting Facebook photos

* Add pagination todo for Photo Export and use Mockito in FacebookPhotosExporterTest.
  • Loading branch information...
wmorland authored and holachuy committed Sep 25, 2018
1 parent 51bfa7d commit 8fc5f32f45d1eb45ac78828b93aab343ea152bd0
Showing with 733 additions and 75 deletions.
  1. +33 −74 client-rest/package-lock.json
  2. +1 −1 client-rest/package.json
  3. +1 −0 distributions/api-default/build.gradle
  4. +1 −0 distributions/demo-google-deployment/api/build.gradle
  5. +2 −0 distributions/demo-server/build.gradle
  6. +1 −0 distributions/transfer-default/build.gradle
  7. +28 −0 extensions/auth/portability-auth-facebook/build.gradle
  8. +110 −0 ...-auth-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookAuthDataGenerator.java
  9. +86 −0 ...th-facebook/src/main/java/org/datatransferproject/auth/facebook/FacebookAuthServiceExtension.java
  10. +1 −0 ...n/resources/META-INF/services/org.datatransferproject.spi.api.auth.extension.AuthServiceExtension
  11. +52 −0 ...h-facebook/src/test/java/org/datatransferproject/auth/facebook/FacebookAuthDataGeneratorTest.java
  12. +28 −0 extensions/data-transfer/portability-data-transfer-facebook/build.gradle
  13. +87 −0 ...r-facebook/src/main/java/org/datatransferproject/transfer/facebook/FacebookTransferExtension.java
  14. +104 −0 ...cebook/src/main/java/org/datatransferproject/transfer/facebook/photos/FacebookPhotosExporter.java
  15. +28 −0 ...ebook/src/main/java/org/datatransferproject/transfer/facebook/photos/FacebookPhotosInterface.java
  16. +47 −0 ...facebook/src/main/java/org/datatransferproject/transfer/facebook/photos/RestFbFacebookPhotos.java
  17. +1 −0 ...main/resources/META-INF/services/org.datatransferproject.spi.transfer.extension.TransferExtension
  18. +105 −0 ...ok/src/test/java/org/datatransferproject/transfer/facebook/photos/FacebookPhotosExporterTest.java
  19. +14 −0 ...types-transfer/src/main/java/org/datatransferproject/types/transfer/models/photos/PhotoModel.java
  20. +3 −0 settings.gradle

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -30,7 +30,7 @@
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.6.8",
"@angular/cli": "~6.1.4",
"@angular/cli": "^6.1.5",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.6",
@@ -32,6 +32,7 @@ dependencies {
compile project(':extensions:auth:portability-auth-google')
compile project(':extensions:auth:portability-auth-microsoft')
compile project(':extensions:auth:portability-auth-flickr')
compile project(':extensions:auth:portability-auth-facebook')
}
addCloudExtensionDependency(project)
@@ -63,6 +63,7 @@ dependencies {
compile project(':extensions:auth:portability-auth-rememberthemilk')
compile project(':extensions:auth:portability-auth-instagram')
compile project(':extensions:auth:portability-auth-smugmug')
compile project(':extensions:auth:portability-auth-facebook')
}
@@ -71,6 +71,7 @@ dependencies {
compile project(':extensions:auth:portability-auth-flickr')
compile project(':extensions:auth:portability-auth-google')
compile project(':extensions:auth:portability-auth-instagram')
compile project(':extensions:auth:portability-auth-facebook')
compile project(':extensions:auth:portability-auth-microsoft')
compile project(':extensions:auth:portability-auth-rememberthemilk')
compile project(':extensions:auth:portability-auth-smugmug')
@@ -79,6 +80,7 @@ dependencies {
compile project(':extensions:data-transfer:portability-data-transfer-flickr')
compile project(':extensions:data-transfer:portability-data-transfer-google')
compile project(':extensions:data-transfer:portability-data-transfer-instagram')
compile project(':extensions:data-transfer:portability-data-transfer-facebook')
compile project(':extensions:data-transfer:portability-data-transfer-microsoft')
compile project(':extensions:data-transfer:portability-data-transfer-rememberthemilk')
compile project(':extensions:data-transfer:portability-data-transfer-smugmug')
@@ -31,6 +31,7 @@ dependencies {
compile project(':extensions:data-transfer:portability-data-transfer-flickr')
compile project(':extensions:data-transfer:portability-data-transfer-google')
compile project(':extensions:data-transfer:portability-data-transfer-microsoft')
compile project(':extensions:data-transfer:portability-data-transfer-facebook')
}
addCloudExtensionDependency(project)
@@ -0,0 +1,28 @@
/*
* Copyright 2018 The Data Transfer Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
dependencies {
compile project(':portability-spi-api')
compile project(':portability-spi-cloud')
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"
compile("com.google.oauth-client:google-oauth-client:${googleApiClient}")
compile("com.google.http-client:google-http-client-jackson2:${googleHttpClientVersion}")
testCompile("org.mockito:mockito-all:${mockitoVersion}")
}
@@ -0,0 +1,110 @@
/*
* Copyright 2018 The Data Transfer Project Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.datatransferproject.auth.facebook;
import com.google.api.client.auth.oauth2.*;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.io.BaseEncoding;
import org.datatransferproject.spi.api.auth.AuthDataGenerator;
import org.datatransferproject.spi.api.types.AuthFlowConfiguration;
import org.datatransferproject.types.transfer.auth.AppCredentials;
import org.datatransferproject.types.transfer.auth.AuthData;
import org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData;
import java.io.IOException;
import java.util.List;
import static org.datatransferproject.types.common.PortabilityCommon.AuthProtocol.OAUTH_2;
public class FacebookAuthDataGenerator implements AuthDataGenerator {
private static final String AUTHORIZATION_SERVER_URL =
"https://www.facebook.com/v3.1/dialog/oauth";
private static final String TOKEN_SERVER_URL =
"https://graph.facebook.com/v3.1/oauth/access_token";
private final AppCredentials appCredentials;
private final HttpTransport httpTransport;
private final List<String> scopes = ImmutableList.of("user_photos");
FacebookAuthDataGenerator(AppCredentials appCredentials, HttpTransport httpTransport) {
this.appCredentials = appCredentials;
this.httpTransport = httpTransport;
}
@Override
public AuthFlowConfiguration generateConfiguration(String callbackUrl, String id) {
String encodedJobId = BaseEncoding.base64Url().encode(id.getBytes(Charsets.UTF_8));
String url =
createFlow()
.newAuthorizationUrl()
.setRedirectUri(callbackUrl)
.setState(encodedJobId)
.build();
return new AuthFlowConfiguration(url, OAUTH_2, getTokenUrl());
}
@Override
public AuthData generateAuthData(
String callbackUrl, String authCode, String id, AuthData initialAuthData, String extra) {
Preconditions.checkArgument(
Strings.isNullOrEmpty(extra), "Extra data not expected for Facebook oauth flow");
Preconditions.checkArgument(
initialAuthData == null, "Earlier auth data not expected for Facebook oauth flow");
AuthorizationCodeFlow flow = createFlow();
TokenResponse response;
try {
response =
flow.newTokenRequest(authCode)
.setRedirectUri(callbackUrl)
.execute();
} catch (IOException e) {
throw new RuntimeException("Error calling AuthorizationCodeFlow.execute ", e);
}
// Figure out storage
Credential credential;
try {
credential = flow.createAndStoreCredential(response, id);
} catch (IOException e) {
throw new RuntimeException(
"Error calling AuthorizationCodeFlow.createAndStoreCredential ", e);
}
return new TokensAndUrlAuthData(
credential.getAccessToken(),
credential.getRefreshToken(),
credential.getTokenServerEncodedUrl());
}
private AuthorizationCodeFlow createFlow() {
return new AuthorizationCodeFlow.Builder(
BearerToken.authorizationHeaderAccessMethod(), // Access Method
httpTransport,
new JacksonFactory(),
new GenericUrl(TOKEN_SERVER_URL),
new ClientParametersAuthentication(
appCredentials.getKey(), appCredentials.getSecret()), // HttpExecuteInterecptor
appCredentials.getKey(), // client ID
AUTHORIZATION_SERVER_URL)
.setScopes(scopes)
.build();
}
}
Oops, something went wrong.

0 comments on commit 8fc5f32

Please sign in to comment.