Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth1 joining #608

Merged
merged 24 commits into from Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/auth/portability-auth-flickr/build.gradle
Expand Up @@ -17,6 +17,7 @@
dependencies {
compile project(':portability-spi-cloud')
compile project(':portability-spi-api')
compile project(':libraries:auth')

compile("org.slf4j:slf4j-api:${slf4jVersion}")
compile("org.slf4j:slf4j-log4j12:${slf4jVersion}")
Expand Down
Expand Up @@ -39,6 +39,7 @@
/*
* {@link AuthDataGenerator} to obtain auth credentials for the Flickr API.
*
* Note: this is in the process of being deprecated in favor of OAuth2DataGenerator.
olsona marked this conversation as resolved.
Show resolved Hide resolved
* <p>TODO(#553): Remove code/token exchange as this will be handled by frontends.
*/
public class FlickrAuthDataGenerator implements AuthDataGenerator {
Expand Down
Expand Up @@ -16,64 +16,10 @@

package org.datatransferproject.auth.flickr;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.util.List;
import org.datatransferproject.api.launcher.ExtensionContext;
import org.datatransferproject.spi.cloud.storage.AppCredentialStore;
import org.datatransferproject.spi.api.auth.AuthDataGenerator;
import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry;
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.datatransferproject.auth.OAuth1ServiceExtension;

public class FlickrAuthServiceExtension implements AuthServiceExtension {
private static final String FLICKR_KEY = "FLICKR_KEY";
private static final String FLICKR_SECRET = "FLICKR_SECRET";
private static final String SERVICE_ID = "FLICKR";

private final Logger logger = LoggerFactory.getLogger(FlickrAuthServiceExtension.class);
private final List<String> supportedServices = ImmutableList.of("PHOTOS");
private FlickrAuthDataGenerator flickrAuthDataGenerator;
private boolean initialized = false;

@Override
public String getServiceId() {
return SERVICE_ID;
}

@Override
public AuthDataGenerator getAuthDataGenerator(
String transferDataType, AuthServiceProviderRegistry.AuthMode mode) {
Preconditions.checkArgument(
initialized,
"FlickrAuthServiceExtension is not initialized! Unable to retrieve AuthDataGenerator");
return flickrAuthDataGenerator;
}

@Override
public List<String> getImportTypes() {
return supportedServices;
}

@Override
public List<String> getExportTypes() {
return supportedServices;
}

@Override
public void initialize(ExtensionContext context) {
AppCredentialStore appCredentialStore = context.getService(AppCredentialStore.class);

try {
flickrAuthDataGenerator =
new FlickrAuthDataGenerator(
appCredentialStore.getAppCredentials(FLICKR_KEY, FLICKR_SECRET));
initialized = true;
} catch (IOException e) {
logger.debug(
"Error retrieving Flickr Credentials. Did you set {} and {}?", FLICKR_KEY, FLICKR_SECRET);
}
public class FlickrAuthServiceExtension extends OAuth1ServiceExtension {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: class docs here & elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

public FlickrAuthServiceExtension() {
super(new FlickrOAuthConfig());
}
}
@@ -0,0 +1,80 @@
/*
* 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.flickr;

import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthSigner;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.datatransferproject.auth.OAuth1Config;

/**
* Class that supplies Flickr-specific OAuth1 info
* See https://www.flickr.com/services/api/auth.oauth.html
*/
public class FlickrOAuthConfig implements OAuth1Config {

@Override
public String getServiceName() {
return "Flickr";
}

@Override
public String getRequestTokenUrl() {
return "https://www.flickr.com/services/oauth/request_token";
}

@Override
public String getAuthorizationUrl() {
return "https://www.flickr.com/services/oauth/authorize";
}

@Override
public String getAccessTokenUrl() {
return "https://www.flickr.com/services/oauth/access_token";
}

@Override
public Map<String, String> getExportScopes() {
return ImmutableMap.of("PHOTOS", "read");
}

@Override
public Map<String, String> getImportScopes() {
return ImmutableMap.of("PHOTOS", "write");
}

@Override
public String getScopeParameterName() {
return "perms";
}

@Override
public OAuthSigner getRequestTokenSigner(String clientSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
return signer;
}

@Override
public OAuthSigner getAccessTokenSigner(String clientSecret, String tokenSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
signer.tokenSharedSecret = tokenSecret;
return signer;
}
}
1 change: 1 addition & 0 deletions extensions/auth/portability-auth-smugmug/build.gradle
Expand Up @@ -17,6 +17,7 @@
dependencies {
compile project(':portability-spi-api')
compile project(':portability-spi-cloud')
compile project(':libraries:auth')

compile("org.slf4j:slf4j-api:${slf4jVersion}")
compile("org.slf4j:slf4j-log4j12:${slf4jVersion}")
Expand Down
Expand Up @@ -37,6 +37,7 @@
/*
* {@link AuthDataGenerator} to obtain auth credentials for the Smugmug API.
*
* Note: this is in the process of being deprecated in favor of OAuth2DataGenerator.
olsona marked this conversation as resolved.
Show resolved Hide resolved
* <p>TODO(#553): Remove code/token exchange as this will be handled by frontends.
*/
public class SmugMugAuthDataGenerator implements AuthDataGenerator {
Expand Down
Expand Up @@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.List;
import org.datatransferproject.api.launcher.ExtensionContext;
import org.datatransferproject.auth.OAuth1ServiceExtension;
import org.datatransferproject.spi.api.auth.AuthDataGenerator;
import org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry.AuthMode;
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;
Expand All @@ -30,70 +31,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/* SmugMugAuthServiceExtension - provides accessors to AuthDataGenerators. */
public class SmugMugAuthServiceExtension implements AuthServiceExtension {

private static final String SMUGMUG_KEY = "SMUGMUG_KEY";
private static final String SMUGMUG_SECRET = "SMUGMUG_SECRET";
private static final String SERVICE_ID = "SMUGMUG";

private final Logger logger = LoggerFactory.getLogger(SmugMugAuthServiceExtension.class);
private final List<String> supportedServices = ImmutableList.of("PHOTOS");
private AuthDataGenerator importAuthDataGenerator;
private AuthDataGenerator exportAuthDataGenerator;
private boolean initialized = false;

@Override
public String getServiceId() {
return SERVICE_ID;
}

@Override
public AuthDataGenerator getAuthDataGenerator(String transferDataType, AuthMode mode) {
Preconditions.checkArgument(
initialized,
"SmugMugAuthServiceExtension is not initialized! Unable to retrieve AuthDataGenerator.");
Preconditions.checkArgument(
supportedServices.contains(transferDataType),
"Transfer type [" + transferDataType + "] is not supported in SmugMug.");
return (mode == AuthMode.IMPORT) ? importAuthDataGenerator : exportAuthDataGenerator;
}

@Override
public List<String> getImportTypes() {
return supportedServices;
}

@Override
public List<String> getExportTypes() {
return supportedServices;
}

@Override
public void initialize(ExtensionContext context) {
if (initialized) {
logger.warn("SmugmugAuthServiceExtension already initialized. Nothing to do.");
return;
}

AppCredentials appCredentials;
try {
appCredentials =
context
.getService(AppCredentialStore.class)
.getAppCredentials(SMUGMUG_KEY, SMUGMUG_SECRET);
} catch (IOException e) {
logger.warn(
"Error retrieving SmugMug credentials. Did you set {} and {}?",
SMUGMUG_KEY,
SMUGMUG_SECRET);
return;
}

importAuthDataGenerator =
new SmugMugAuthDataGenerator(appCredentials, AuthMode.IMPORT);
exportAuthDataGenerator =
new SmugMugAuthDataGenerator(appCredentials, AuthMode.EXPORT);
initialized = true;
public class SmugMugAuthServiceExtension extends OAuth1ServiceExtension {
public SmugMugAuthServiceExtension() {
super(new SmugMugOAuthConfig());
}
}
@@ -0,0 +1,80 @@
/*
* 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.smugmug;

import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthSigner;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import org.datatransferproject.auth.OAuth1Config;

/**
* Class that supplies SmugMug-specific OAuth1 info
* See https://smugmug.atlassian.net/wiki/spaces/API/pages/689052/OAuth
*/
public class SmugMugOAuthConfig implements OAuth1Config {

@Override
public String getServiceName() {
return "SmugMug";
}

@Override
public String getRequestTokenUrl() {
return "https://secure.smugmug.com/services/oauth/1.0a/getRequestToken";
}

@Override
public String getAuthorizationUrl() {
return "https://secure.smugmug.com/services/oauth/1.0a/authorize";
}

@Override
public String getAccessTokenUrl() {
return "https://secure.smugmug.com/services/oauth/1.0a/getAccessToken";
}

@Override
public Map<String, String> getExportScopes() {
return ImmutableMap.of("PHOTOS", "Read");
}

@Override
public Map<String, String> getImportScopes() {
return ImmutableMap.of("PHOTOS", "Add");
}

@Override
public String getScopeParameterName() {
return "Permissions";
}

@Override
public OAuthSigner getRequestTokenSigner(String clientSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
return signer;
}

@Override
public OAuthSigner getAccessTokenSigner(String clientSecret, String tokenSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
signer.tokenSharedSecret = tokenSecret;
return signer;
}
}
Expand Up @@ -39,6 +39,7 @@
/*
* {@link AuthDataGenerator} to obtain auth credentials for the Twitter API.
*
* Note: this is in the process of being deprecated in favor of OAuth2DataGenerator.
olsona marked this conversation as resolved.
Show resolved Hide resolved
* <p>TODO(#553): Remove code/token exchange as this will be handled by frontends.
*/
final class TwitterAuthDataGenerator implements AuthDataGenerator {
Expand Down