Skip to content

Commit

Permalink
Adding some docs, removing scopes requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna Olson committed Oct 17, 2018
1 parent b63b0b4 commit a06c4aa
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 73 deletions.
Expand Up @@ -17,8 +17,13 @@
package org.datatransferproject.auth.flickr;

import org.datatransferproject.auth.OAuth1ServiceExtension;
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;

/**
* An {@link AuthServiceExtension} providing an authentication mechanism for Flickr services.
*/
public class FlickrAuthServiceExtension extends OAuth1ServiceExtension {

public FlickrAuthServiceExtension() {
super(new FlickrOAuthConfig());
}
Expand Down
Expand Up @@ -62,19 +62,4 @@ public Map<String, String> getImportScopes() {
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;
}
}
Expand Up @@ -19,7 +19,7 @@
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;

/**
* An {@link AuthServiceExtension} providing authentication mechanism for Google services.
* An {@link AuthServiceExtension} providing an authentication mechanism for Google services.
*/
public class GoogleAuthServiceExtension extends OAuth2ServiceExtension {

Expand Down
Expand Up @@ -15,9 +15,12 @@
*/
package org.datatransferproject.auth.instagram;


import org.datatransferproject.auth.OAuth2ServiceExtension;
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;

/**
* An {@link AuthServiceExtension} providing an authentication mechanism for Instagram services.
*/
public class InstagramAuthServiceExtension extends OAuth2ServiceExtension {

public InstagramAuthServiceExtension() {
Expand Down
Expand Up @@ -16,22 +16,14 @@

package org.datatransferproject.auth.smugmug;

import com.google.api.client.http.HttpTransport;
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.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;
import org.datatransferproject.spi.cloud.storage.AppCredentialStore;
import org.datatransferproject.types.transfer.auth.AppCredentials;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An {@link AuthServiceExtension} providing an authentication mechanism for SmugMug services.
*/
public class SmugMugAuthServiceExtension extends OAuth1ServiceExtension {

public SmugMugAuthServiceExtension() {
super(new SmugMugOAuthConfig());
}
Expand Down
Expand Up @@ -62,19 +62,4 @@ public Map<String, String> getImportScopes() {
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 @@ -17,7 +17,11 @@
package org.datatransferproject.auth.twitter;

import org.datatransferproject.auth.OAuth1ServiceExtension;
import org.datatransferproject.spi.api.auth.extension.AuthServiceExtension;

/**
* An {@link AuthServiceExtension} providing an authentication mechanism for Twitter services.
*/
public class TwitterAuthServiceExtension extends OAuth1ServiceExtension {

public TwitterAuthServiceExtension() {
Expand Down
Expand Up @@ -69,19 +69,4 @@ public String getScopeParameterName() {
public OAuth1Step whenAddScopes() {
return OAuth1Step.REQUEST_TOKEN;
}

@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 @@ -69,12 +69,21 @@ default OAuth1Step whenAddScopes() {
/**
* Returns the {@link OAuthSigner} for the initial token request
*/
OAuthSigner getRequestTokenSigner(String clientSecret);
default OAuthSigner getRequestTokenSigner(String clientSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
return signer;
}

/**
* Returns the {@link OAuthSigner} for the access token request
*/
OAuthSigner getAccessTokenSigner(String clientSecret, String tokenSecret);
default OAuthSigner getAccessTokenSigner(String clientSecret, String tokenSecret) {
OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = clientSecret;
signer.tokenSharedSecret = tokenSecret;
return signer;
}

enum OAuth1Step {
REQUEST_TOKEN,
Expand Down
Expand Up @@ -73,7 +73,7 @@ public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, Strin
tempTokenRequest.transport = httpTransport;
tempTokenRequest.consumerKey = clientId;
tempTokenRequest.signer = config.getRequestTokenSigner(clientSecret);
if (config.whenAddScopes() == OAuth1Step.REQUEST_TOKEN) {
if (config.whenAddScopes() == OAuth1Step.REQUEST_TOKEN && !Strings.isNullOrEmpty(scope)) {
tempTokenRequest.set(config.getScopeParameterName(), scope);
}
TokenSecretAuthData authData;
Expand All @@ -89,7 +89,7 @@ public AuthFlowConfiguration generateConfiguration(String callbackBaseUrl, Strin
OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(
config.getAuthorizationUrl());
authorizeUrl.temporaryToken = authData.getToken();
if (config.whenAddScopes() == OAuth1Step.AUTHORIZATION) {
if (config.whenAddScopes() == OAuth1Step.AUTHORIZATION && !Strings.isNullOrEmpty(scope)) {
authorizeUrl.set(config.getScopeParameterName(), scope);
}
String url = authorizeUrl.build();
Expand Down Expand Up @@ -133,9 +133,5 @@ private void validateConfig() {
"Config is missing authorization url");
Preconditions.checkArgument(!Strings.isNullOrEmpty(config.getAccessTokenUrl()),
"Config is missing access token url");
Preconditions
.checkArgument(config.getExportScopes() != null, "Config is missing export scopes");
Preconditions
.checkArgument(config.getImportScopes() != null, "Config is missing import scopes");
}
}
Expand Up @@ -117,8 +117,11 @@ private AuthorizationCodeFlow createFlow() {
new ClientParametersAuthentication(
clientId, clientSecret), // HttpExecuteInterceptor
clientId, // client ID
config.getAuthUrl())
.setScopes(scopes);
config.getAuthUrl());

if (scopes != null && scopes.size() > 0) {
authCodeFlowBuilder.setScopes(scopes);
}

return authCodeFlowBuilder.build();
}
Expand All @@ -130,9 +133,5 @@ private void validateConfig() {
.checkArgument(!Strings.isNullOrEmpty(config.getAuthUrl()), "Config is missing auth url");
Preconditions
.checkArgument(!Strings.isNullOrEmpty(config.getTokenUrl()), "Config is missing token url");
Preconditions
.checkArgument(config.getExportScopes() != null, "Config is missing export scopes");
Preconditions
.checkArgument(config.getImportScopes() != null, "Config is missing import scopes");
}
}

0 comments on commit a06c4aa

Please sign in to comment.